22 Commits

Author SHA1 Message Date
7f90c70c30 Update COPYRIGHT and LICENSE contents to align with the house standard
All checks were successful
ci/woodpecker/push/verify Pipeline was successful
2026-09-26 15:05:03 -05:00
b750c42ad6 Remove legacy manifest provenance decoding
All checks were successful
ci/woodpecker/push/verify Pipeline was successful
2026-09-25 19:45:19 +00:00
73c4986f3d Preserve Audita module selections in YAML output 2026-09-25 19:42:22 +00:00
e5c06019b3 Record migration review findings 2026-09-25 18:28:38 +00:00
fae18bf4a7 Verify shared provider credentials across both adapters 2026-09-25 16:06:02 +00:00
e5c1029165 Document Audita v2 operator migration and examples 2026-09-25 16:00:27 +00:00
2d167d0d67 Track Audita v2 selections in polish resume evidence 2026-09-25 15:55:38 +00:00
569f467393 Archive Audita reports as polish diagnostics 2026-09-25 15:51:18 +00:00
77d9d57937 Adopt Audita v2 configuration and subprocess contract 2026-09-25 15:45:02 +00:00
7e0151ef93 Migrate Notarius to credential lists 2026-09-25 15:33:46 +00:00
49948852d6 Add shared resolved credential forwarding 2026-09-25 15:26:51 +00:00
83eaa960ec Adopt ConfigKit overlays for pipeline selection 2026-09-25 15:24:03 +00:00
e27c49e946 Track repository agent instructions 2026-09-25 15:11:56 +00:00
625e6edfd7 Align repository policies with shared standards 2026-09-25 15:11:08 +00:00
17cef0700a Add ConfigKit overlay migration to the plan 2026-09-25 15:04:55 +00:00
55c102c9ed Plan the Audita v2 migration 2026-09-25 14:50:25 +00:00
70f1dbfb59 Prepare the v2.2.1 release
All checks were successful
ci/woodpecker/push/verify Pipeline was successful
ci/woodpecker/tag/release Pipeline was successful
2026-09-22 18:18:45 +00:00
f1575effc2 Document shared checkpoint persistence 2026-09-22 15:13:46 +00:00
7e39a1d51f Delegate transcription checkpoints to shared persistence 2026-09-22 15:12:11 +00:00
3722e572df Delegate analyze checkpoints to shared persistence 2026-09-22 15:09:29 +00:00
7147e95252 Add shared stage checkpoint persistence 2026-09-22 15:05:25 +00:00
9f2cfddce6 Plan shared stage checkpoint mechanics 2026-09-22 14:54:34 +00:00
95 changed files with 4510 additions and 2572 deletions

2
.gitignore vendored
View File

@@ -1,6 +1,5 @@
# ---> Codex # ---> Codex
.codex .codex
AGENTS.md
.DS_Store .DS_Store
@@ -52,4 +51,3 @@ pipeline.yml
# Built Visual Studio Code Extensions # Built Visual Studio Code Extensions
*.vsix *.vsix

5
AGENTS.md Normal file
View File

@@ -0,0 +1,5 @@
Please review `docs/development.md` for initial orientation in this repository
and follow its task-specific reading guide.
Review and follow `docs/policy/agents.md` before recommending, planning, or
implementing any changes to this repository.

19
COPYRIGHT Normal file
View File

@@ -0,0 +1,19 @@
Narratio
Copyright (C) 2026 Eric Rakestraw
SPDX-License-Identifier: GPL-3.0-or-later
Narratio is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The GNU General Public License version 3 is provided in LICENSE.
Narratio is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
Third-party code and assets are subject to their respective license terms.

892
LICENSE
View File

@@ -1,232 +1,674 @@
GNU GENERAL PUBLIC LICENSE GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007 Version 3, 29 June 2007
Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/> Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. of this license document, but changing it is not allowed.
Preamble Preamble
The GNU General Public License is a free, copyleft license for software and other kinds of works. The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
The licenses for most software and other practical works are designed
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. your programs, too.
For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
The precise terms and conditions for copying, distribution and modification follow.
To protect your rights, we need to prevent others from denying you
TERMS AND CONDITIONS these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
0. Definitions. you modify it: responsibilities to respect the freedom of others.
“This License” refers to version 3 of the GNU General Public License. For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations. know their rights.
To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work. Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
A “covered work” means either the unmodified Program or a work based on the Program. giving you legal permission to copy, distribute and/or modify it.
To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. authors of previous versions.
1. Source Code. Some devices are designed to deny users access to install or run
The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work. modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. of the GPL, as needed to protect the freedom of users.
The Corresponding Source for a work in source code form is that same work. Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
2. Basic Permissions. software on general-purpose computers, but in those that do, we wish to
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. patents cannot be used to render the program non-free.
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. The precise terms and conditions for copying, distribution and
modification follow.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. TERMS AND CONDITIONS
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 0. Definitions.
4. Conveying Verbatim Copies. "This License" refers to version 3 of the GNU General Public License.
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
"Copyright" also means copyright-like laws that apply to other kinds of
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. works, such as semiconductor masks.
5. Conveying Modified Source Versions. "The Program" refers to any copyrightable work licensed under this
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
To "modify" a work means to copy from or adapt all or part of the work
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”. in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. earlier work or a work "based on" the earlier work.
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A "covered work" means either the unmodified Program or a work based
on the Program.
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
To "propagate" a work means to do anything with it that, without
6. Conveying Non-Source Forms. permission, would make you directly or secondarily liable for
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. distribution (with or without modification), making available to the
public, and in some countries other activities as well.
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
To "convey" a work means any kind of propagation that enables other
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
An interactive user interface displays "Appropriate Legal Notices"
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. menu, a prominent item in the list meets this criterion.
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). 1. Source Code.
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. form of a work.
7. Additional Terms. A "Standard Interface" means an interface that either is an official
“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. is widely used among developers working in that language.
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or "Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or (if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
The "Corresponding Source" for a work in object code form means all
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
8. Termination. linked subprograms that the work is specifically designed to require,
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). such as by intimate data communication or control flow between those
subprograms and other parts of the work.
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
The Corresponding Source need not include anything that users
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. can regenerate automatically from other parts of the Corresponding
Source.
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
The Corresponding Source for a work in source code form is that
9. Acceptance Not Required for Having Copies. same work.
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
2. Basic Permissions.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
11. Patents. rights of fair use or other equivalent, as provided by copyright law.
A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”.
You may make, run and propagate covered works that you do not
A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. your copyrighted material outside their relationship with you.
A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. makes it unnecessary.
12. No Surrender of Others' Freedom. 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
No covered work shall be deemed part of an effective technological
13. Use with the GNU Affero General Public License. measure under any applicable law fulfilling obligations under article
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
14. Revised Versions of this License. measures.
The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
When you convey a covered work, you waive any legal power to forbid
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. users, your or third parties' legal rights to forbid circumvention of
technological measures.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 4. Conveying Verbatim Copies.
16. Limitation of Liability. You may convey verbatim copies of the Program's source code as you
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
17. Interpretation of Sections 15 and 16. keep intact all notices stating that this License and any
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
END OF TERMS AND CONDITIONS recipients a copy of this License along with the Program.
How to Apply These Terms to Your New Programs You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
5. Conveying Modified Source Versions.
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
You may convey a work based on the Program, or the modifications to
narratio produce it from the Program, in the form of source code under the
Copyright (C) 2026 eric terms of section 4, provided that you also meet all of these conditions:
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
b) The work must carry prominent notices stating that it is
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail. Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
narratio Copyright (C) 2026 eric <program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”. The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see <https://www.gnu.org/licenses/>. You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read <https://www.gnu.org/philosophy/why-not-lgpl.html>. The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

View File

@@ -44,7 +44,7 @@ Most session-aware commands accept:
- `--session <session.yml>` - `--session <session.yml>`
- `--session-id <session_id>` - `--session-id <session_id>`
- `--previous-session-id <session_id>` - `--previous-session-id <session_id>`
- `--profile <name>` - `--overlay <name>`
- `--secrets-dir <directory>` - `--secrets-dir <directory>`
Rules: Rules:
@@ -54,9 +54,9 @@ Rules:
- if both positional `<session_id>` and `--session-id` are provided, values must match. - if both positional `<session_id>` and `--session-id` are provided, values must match.
- `--previous-session-id` is a strict expectation: the selected session file - `--previous-session-id` is a strict expectation: the selected session file
must contain the same `previous_session_id`. must contain the same `previous_session_id`.
- `--profile` selects `profiles/<name>.yml` relative to the pipeline root. It - `--overlay` selects `overlays/<name>.yml` relative to the pipeline root. It
may be supplied once; omitted, empty, and the exact name `default` select the may be supplied once; omitted, empty, and the exact name `default` select the
base configuration, while an unknown named profile fails. The same selection base configuration, while an unknown named overlay fails. The same selection
applies to all common-flag commands, including `regenerate-artifacts`. applies to all common-flag commands, including `regenerate-artifacts`.
- `--secrets-dir` selects ConfigKit credential-file bootstrap explicitly. A - `--secrets-dir` selects ConfigKit credential-file bootstrap explicitly. A
relative value uses caller CWD. Without the flag, a present `secrets/` relative value uses caller CWD. Without the flag, a present `secrets/`
@@ -85,20 +85,20 @@ Commands with additional positionals keep their command-specific order:
### `config validate`, `config show`, `config sources`, `config artifacts`, and `config diff` ### `config validate`, `config show`, `config sources`, `config artifacts`, and `config diff`
```bash ```bash
narratio config validate [--config <pipeline.yml>] [--campaign <id> | --campaign-file <campaign.yml>] [--profile <name>] [--secrets-dir <directory>] narratio config validate [--config <pipeline.yml>] [--campaign <id> | --campaign-file <campaign.yml>] [--overlay <name>] [--secrets-dir <directory>]
narratio config show [--config <pipeline.yml>] [--campaign <id> | --campaign-file <campaign.yml>] [--profile <name>] [--secrets-dir <directory>] narratio config show [--config <pipeline.yml>] [--campaign <id> | --campaign-file <campaign.yml>] [--overlay <name>] [--secrets-dir <directory>]
narratio config sources [--config <pipeline.yml>] [--campaign <id> | --campaign-file <campaign.yml>] [--profile <name>] [--secrets-dir <directory>] narratio config sources [--config <pipeline.yml>] [--campaign <id> | --campaign-file <campaign.yml>] [--overlay <name>] [--secrets-dir <directory>]
narratio config artifacts [--config <pipeline.yml>] [--campaign <id> | --campaign-file <campaign.yml>] [--profile <name>] [--secrets-dir <directory>] narratio config artifacts [--config <pipeline.yml>] [--campaign <id> | --campaign-file <campaign.yml>] [--overlay <name>] [--secrets-dir <directory>]
narratio config diff <left-profile> <right-profile> [--config <pipeline.yml>] [--campaign <id> | --campaign-file <campaign.yml>] [--secrets-dir <directory>] narratio config diff <left-overlay> <right-overlay> [--config <pipeline.yml>] [--campaign <id> | --campaign-file <campaign.yml>] [--secrets-dir <directory>]
``` ```
These commands resolve the selected profile, defaults, ordinary paths, and—if These commands resolve the selected overlay, defaults, ordinary paths, and—if
a campaign is selected—the campaign-owned party. They neither discover or load a campaign is selected—the campaign-owned party. They neither discover or load
a session nor create a workspace, manifest, run, lock, adapter, or remote a session nor create a workspace, manifest, run, lock, adapter, or remote
connection. Like every pipeline-loading command, they bootstrap the selected or connection. Like every pipeline-loading command, they bootstrap the selected or
conventional secrets directory before resolving configuration; `config show` conventional secrets directory before resolving configuration; `config show`
never includes bootstrap reports or secret values in its YAML output. never includes bootstrap reports or secret values in its YAML output.
Typed credential references, including `notarius.llm_api_key`, must therefore Typed credential references, including `notarius.credentials[]`, must therefore
resolve even though these inspection commands never construct an adapter. resolve even though these inspection commands never construct an adapter.
Campaign selection is optional for a pipeline without party-driven artifact Campaign selection is optional for a pipeline without party-driven artifact
@@ -107,7 +107,7 @@ configured default campaign so Narratio can expand its concrete artifacts and
publish rules. `--campaign` and `--campaign-file` remain mutually exclusive. publish rules. `--campaign` and `--campaign-file` remain mutually exclusive.
Session, range, force, and artifact-execution flags are not accepted. Session, range, force, and artifact-execution flags are not accepted.
`config validate` writes a concise root-path, selected-profile (or `none`), and `config validate` writes a concise root-path, selected-overlay (or `none`), and
effective-digest summary after successful complete validation. `config show` effective-digest summary after successful complete validation. `config show`
writes one deterministic, secret-free YAML document containing defaulted and writes one deterministic, secret-free YAML document containing defaulted and
expanded concrete configuration. It omits ConfigKit directives, artifact expanded concrete configuration. It omits ConfigKit directives, artifact
@@ -115,9 +115,9 @@ family declarations, and runtime provenance.
`config sources` reports the same fully validated resolution without printing `config sources` reports the same fully validated resolution without printing
effective values. Its header identifies the root, ordered imports, selected effective values. Its header identifies the root, ordered imports, selected
profile and overlay, selected campaign, party source, and digest. The overlay and its file, selected campaign, party source, and digest. The
remaining tab-separated records are sorted as `path`, `role`, and `source`. remaining tab-separated records are sorted as `path`, `role`, and `source`.
Roles distinguish root, import, profile, centralized default, campaign, party, Roles distinguish root, import, overlay, centralized default, campaign, party,
and generated family ownership. A generated party member has and generated family ownership. A generated party member has
one family record and one party record at the same logical path. The output one family record and one party record at the same logical path. The output
never reads or prints secret values. never reads or prints secret values.
@@ -133,14 +133,14 @@ party-driven families retain the campaign requirement. See
[Scriptorium Artifact Entries](./config.md#scriptorium-artifact-entries) for the [Scriptorium Artifact Entries](./config.md#scriptorium-artifact-entries) for the
configuration layout. configuration layout.
`config diff` resolves both supplied profile names independently and compares `config diff` resolves both supplied overlay names independently and compares
their fully resolved, secret-free effective mappings. It does their fully resolved, secret-free effective mappings. It does
not accept `--profile`; the two positional names must be distinct, declared not accept `--overlay`; the two positional names must be distinct, valid
profiles. When party-driven families are present, both profiles must resolve to overlays. When party-driven families are present, both overlays must resolve to
the same selected campaign and party. Use `--campaign-file` if profile-specific the same selected campaign and party. Use `--campaign-file` if overlay-specific
campaign configuration would otherwise select different files. campaign configuration would otherwise select different files.
Equal profiles print `no differences`. Otherwise, sorted tab-separated records Equal overlays print `no differences`. Otherwise, sorted tab-separated records
use one of these forms, with compact JSON values: use one of these forms, with compact JSON values:
```text ```text
@@ -151,7 +151,7 @@ changed <path> <left-value> <right-value>
Mappings are flattened to their logical field paths; lists remain one atomic Mappings are flattened to their logical field paths; lists remain one atomic
value. The command compares defaulted concrete artifacts and publish rules, not value. The command compares defaulted concrete artifacts and publish rules, not
profile names, source-file layout, or formatting. It succeeds when differences overlay names, source-file layout, or formatting. It succeeds when differences
are found, making it suitable for review and migration checks. are found, making it suitable for review and migration checks.
### `version` ### `version`
@@ -178,7 +178,7 @@ Behavior:
- runs `render` before `extract`; an omitted or disabled Notarius - runs `render` before `extract`; an omitted or disabled Notarius
configuration records an explicit `notarius_disabled` self-skip; configuration records an explicit `notarius_disabled` self-skip;
- resolves every selected typed credential during the initial configuration - resolves every selected typed credential during the initial configuration
load, including a Notarius credential when extract is disabled, outside the load, including Notarius credentials when extract is disabled, outside the
selected range, or later skipped as resumable; selected range, or later skipped as resumable;
- skips already-succeeded stages unless `--force` is set or a stage-specific - skips already-succeeded stages unless `--force` is set or a stage-specific
resume check finds its durable result obsolete; resume check finds its durable result obsolete;
@@ -189,7 +189,7 @@ Behavior:
- writes the session manifest as the sole durable progress ledger. Each - writes the session manifest as the sole durable progress ledger. Each
invocation also creates its run-local directory and returns an immediate invocation also creates its run-local directory and returns an immediate
command summary; neither creates another durable progress record. command summary; neither creates another durable progress record.
- reports the resolved profile (or `none`) and effective configuration digest. - reports the resolved overlay (or `none`) and effective configuration digest.
When `--artifacts` is present, the selected range must contain `analyze` or When `--artifacts` is present, the selected range must contain `analyze` or
`publish`. Either consumer is sufficient, including a one-stage range. `publish`. Either consumer is sufficient, including a one-stage range.
@@ -304,7 +304,7 @@ Uses the same inclusive bounds, endpoint validation, force scope, and artifact
selection contract as `run`. It validates config and prints run/skip decisions selection contract as `run`. It validates config and prints run/skip decisions
for selected stages only without creating the local workdir or changing the for selected stages only without creating the local workdir or changing the
manifest. Resume-capable selected stages are checked against durable evidence. manifest. Resume-capable selected stages are checked against durable evidence.
The output includes the resolved profile (or `none`) and effective configuration The output includes the resolved overlay (or `none`) and effective configuration
digest without writing provenance or any manifest state. digest without writing provenance or any manifest state.
For `analyze`, the preview also lists explicit targets, prerequisite-only work, For `analyze`, the preview also lists explicit targets, prerequisite-only work,
execution order, and reusable current artifacts with concise reasons. These execution order, and reusable current artifacts with concise reasons. These

View File

@@ -47,24 +47,24 @@ the durable copied session input.
`narratio config validate`, `narratio config show`, `narratio config sources`, `narratio config validate`, `narratio config show`, `narratio config sources`,
and `narratio config artifacts` use the same `--config`, `--campaign`, and `narratio config artifacts` use the same `--config`, `--campaign`,
`--campaign-file`, and `--campaign-file`, and
`--profile` selection rules as pipeline commands, but do not select, discover, `--overlay` selection rules as pipeline commands, but do not select, discover,
or load a session. They resolve configured typed credential references as part or load a session. They resolve configured typed credential references as part
of the ordinary ConfigKit load but expose only their environment-variable names; of the ordinary ConfigKit load but expose only their environment-variable names;
they do not create runtime state. they do not create runtime state.
`narratio config diff <left-profile> <right-profile>` uses the same pipeline and `narratio config diff <left-overlay> <right-overlay>` uses the same pipeline and
campaign selectors, resolves each named profile with an independent ConfigKit campaign selectors, resolves each named overlay with an independent ConfigKit
load, and does not accept a separate `--profile` flag. load, and does not accept a separate `--overlay` flag.
Campaign selection is optional only when the resolved pipeline has no Campaign selection is optional only when the resolved pipeline has no
`scriptorium.artifact_families`. When families are declared, Narratio selects a `scriptorium.artifact_families`. When families are declared, Narratio selects a
campaign through an explicit flag or `pipeline.campaigns.default_campaign_id`, campaign through an explicit flag or `pipeline.campaigns.default_campaign_id`,
then parses the campaign-owned party and expands concrete artifacts and any then parses the campaign-owned party and expands concrete artifacts and any
family publish rules before validation. `config validate` prints the resulting family publish rules before validation. `config validate` prints the resulting
root, profile, and effective digest. `config show` emits the normalized root, overlay, and effective digest. `config show` emits the normalized
effective pipeline YAML, with defaults and concrete expansion included but effective pipeline YAML, with defaults and concrete expansion included but
ConfigKit directives and family declarations omitted. This review projection is ConfigKit directives and family declarations omitted. This review projection is
not promised to be a reloadable authoring document. `config sources` prints a stable not promised to be a reloadable authoring document. `config sources` prints a stable
source projection instead of effective values: root/import/profile/default source projection instead of effective values: root/import/overlay/default
ownership plus campaign/party and generated-family records. Canonical derived ownership plus campaign/party and generated-family records. Canonical derived
players trace to the party. `config artifacts` lists the concrete artifact map, players trace to the party. `config artifacts` lists the concrete artifact map,
effective dependencies, and defining sources. The [CLI reference](cli.md#config-validate-config-show-config-sources-config-artifacts-and-config-diff) effective dependencies, and defining sources. The [CLI reference](cli.md#config-validate-config-show-config-sources-config-artifacts-and-config-diff)
@@ -83,7 +83,7 @@ difference.
Use the [production/testing bundle](../examples/production-testing/pipeline.yml) Use the [production/testing bundle](../examples/production-testing/pipeline.yml)
as the complete copyable migration reference. Keep production settings in the as the complete copyable migration reference. Keep production settings in the
base, split them into explicit additive imports, and place testing differences base, split them into explicit additive imports, and place testing differences
in the fixed `profiles/testing.yml` overlay. Put ordinary artifacts and families in the fixed `overlays/testing.yml` overlay. Put ordinary artifacts and families
in the recommended one-definition files shown by that bundle. Convert campaign in the recommended one-definition files shown by that bundle. Convert campaign
rosters to [canonical party input](integrations/party.md), then express character rosters to [canonical party input](integrations/party.md), then express character
work as families. Inspect the result with `config validate`, `config show`, work as families. Inspect the result with `config validate`, `config show`,
@@ -108,11 +108,14 @@ remote state with an unsafe legacy identity must be migrated before use.
root-only `configkit.imports` list. Imported files contribute fields to one root-only `configkit.imports` list. Imported files contribute fields to one
logical pipeline document; they do not override fields supplied by the root logical pipeline document; they do not override fields supplied by the root
or another import. or another import.
- An omitted profile, an empty profile option, and the exact name `default` - An omitted overlay, an empty overlay option, and the exact name `default`
select the base configuration. Any other name selects select the base configuration. Any other name selects
`profiles/<name>.yml` relative to the pipeline root. `overlays/<name>.yml` relative to the pipeline root. Move previously selected
`profiles/<name>.yml` files there; the old directory is not searched, and
`--profile` is no longer accepted for Narratio pipeline selection. Explicit
imports from a directory named `profiles` remain valid.
- Campaign, session, and canonical-party documents are strict single-source - Campaign, session, and canonical-party documents are strict single-source
ConfigKit schemas. They do not enable imports, profiles, or `configkit` ConfigKit schemas. They do not enable imports, overlays, or `configkit`
directives. directives.
- Configured timeout and retry-delay durations must be positive. An omitted - Configured timeout and retry-delay durations must be positive. An omitted
artifact timeout continues to inherit its configured Scriptorium timeout. artifact timeout continues to inherit its configured Scriptorium timeout.
@@ -137,10 +140,10 @@ remote state with an unsafe legacy identity must be migrated before use.
- local (`audio_dir` or `audio_files`), or - local (`audio_dir` or `audio_files`), or
- S3 (`audio_s3.prefix`). - S3 (`audio_s3.prefix`).
### Pipeline imports and profiles ### Pipeline imports and overlays
Large pipeline configurations may be split into explicitly named fragments and Large pipeline configurations may be split into explicitly named fragments and
may use fixed-path profile overlays: may use fixed-path selected overlays:
```yaml ```yaml
configkit: configkit:
@@ -170,12 +173,12 @@ name the full field path and every source that claimed it. Narratio additionally
rejects an artifact or artifact-family key declared by more than one base file, rejects an artifact or artifact-family key declared by more than one base file,
even when those files contribute disjoint children. even when those files contribute disjoint children.
Profile names are case-sensitive and use ConfigKit's safe fixed-path naming Overlay names are case-sensitive and use ConfigKit's safe fixed-path naming
rules. Only the selected overlay is opened; a malformed unselected overlay does rules. Only the selected overlay is opened; a malformed unselected overlay does
not affect a base or different-profile load. Maps merge recursively, overlay not affect a base or different-overlay load. Maps merge recursively, overlay
scalars replace base scalars, and overlay lists replace base lists completely. scalars replace base scalars, and overlay lists replace base lists completely.
Explicit `false`, zero, empty strings, empty containers, and null values remain Explicit `false`, zero, empty strings, empty containers, and null values remain
explicit inputs and are not refilled by defaults. Profiles cannot inherit, explicit inputs and are not refilled by defaults. Overlays cannot inherit,
stack, import files, or declare another ConfigKit control section. stack, import files, or declare another ConfigKit control section.
During ConfigKit loading, Narratio applies fresh typed defaults, recorded During ConfigKit loading, Narratio applies fresh typed defaults, recorded
@@ -183,7 +186,7 @@ entry-level defaults and normalization, read-only file-local validation, and
ordinary path resolution before computing a deterministic effective ordinary path resolution before computing a deterministic effective
configuration digest. The digest represents the normalized, secret-free configuration digest. The digest represents the normalized, secret-free
runtime pipeline mapping; it excludes ConfigKit directives, source runtime pipeline mapping; it excludes ConfigKit directives, source
provenance, profile identity, and raw environment secret values. Equivalent provenance, overlay identity, and raw environment secret values. Equivalent
effective mappings therefore have the same digest regardless of how fields are effective mappings therefore have the same digest regardless of how fields are
split among the root and imports. split among the root and imports.
@@ -227,7 +230,7 @@ inputs:
- Do not place raw secrets in YAML. - Do not place raw secrets in YAML.
- Credential fields contain environment-variable names, represented internally - Credential fields contain environment-variable names, represented internally
as ConfigKit typed secret references (for example as ConfigKit typed secret references (for example
`pipeline.notarius.llm_api_key: NOTARIUS_LLM_API_KEY`). A configured reference `pipeline.notarius.credentials: [NOTARIUS_LLM_API_KEY]`). A configured reference
must resolve to a nonempty environment value during load. must resolve to a nonempty environment value during load.
- Every surviving reference is resolved during ordinary pipeline loading, - Every surviving reference is resolved during ordinary pipeline loading,
regardless of whether its integration is disabled, outside the selected regardless of whether its integration is disabled, outside the selected
@@ -331,19 +334,14 @@ Rules:
| `pipeline.seriatim.env.filler_max_duration` | float | No | unset | | `pipeline.seriatim.env.filler_max_duration` | float | No | unset |
| `pipeline.audita.binary` | string | No | `audita` | | `pipeline.audita.binary` | string | No | `audita` |
| `pipeline.audita.timeout` | duration | No | `3h` | | `pipeline.audita.timeout` | duration | No | `3h` |
| `pipeline.audita.llm_api_key` | secret reference | No | unset | | `pipeline.audita.credentials[]` | list[secret reference] | No | empty; exact environment-variable names forwarded to Audita |
| `pipeline.audita.modules[]` | list[string] | No | empty | | `pipeline.audita.modules[]` | list[string] | No | unset; omit to use Audita defaults, set `[]` for no modules |
| `pipeline.audita.base_url` | string | No | empty | | `pipeline.audita.overlay` | string | No | empty; no downstream overlay override |
| `pipeline.audita.model` | string | No | empty | | `pipeline.audita.proposal_profile` | string | No | empty; no downstream proposal-profile override |
| `pipeline.audita.total_llm_concurrency` | int | No | unset | | `pipeline.audita.validation_profile` | string | No | empty; no downstream validation-profile override |
| `pipeline.audita.proposal_llm_concurrency` | int | No | unset |
| `pipeline.audita.validation_model` | string | No | empty |
| `pipeline.audita.validation_llm_concurrency` | int | No | unset |
| `pipeline.audita.transcript_description` | string | No | empty | | `pipeline.audita.transcript_description` | string | No | empty |
| `pipeline.audita.config_path` | string | No | empty | | `pipeline.audita.config_path` | string | No | empty |
| `pipeline.audita.output_schema` | string | No | empty | | `pipeline.audita.output_schema` | string | No | empty |
| `pipeline.audita.work_dir_retention` | string | No | empty |
| `pipeline.audita.report` | bool | No | `true` |
| `pipeline.normalize.output_path` | string | No | `transcripts/final.json` | | `pipeline.normalize.output_path` | string | No | `transcripts/final.json` |
| `pipeline.normalize.output_schema` | string | No | `seriatim-intermediate` | | `pipeline.normalize.output_schema` | string | No | `seriatim-intermediate` |
| `pipeline.normalize.report` | bool | No | `true` | | `pipeline.normalize.report` | bool | No | `true` |
@@ -359,7 +357,7 @@ Rules:
| `pipeline.trim.seriatim.report` | bool | No | `false` | | `pipeline.trim.seriatim.report` | bool | No | `false` |
| `pipeline.notarius.enabled` | bool | No | `false` | | `pipeline.notarius.enabled` | bool | No | `false` |
| `pipeline.notarius.binary` | string | No | `notarius` | | `pipeline.notarius.binary` | string | No | `notarius` |
| `pipeline.notarius.llm_api_key` | secret reference | No | unset; exact environment-variable name forwarded to Notarius | | `pipeline.notarius.credentials[]` | list[secret reference] | No | empty; exact environment-variable names forwarded to Notarius |
| `pipeline.notarius.config_profile` | string | No | unset; exact Notarius ConfigKit profile selector | | `pipeline.notarius.config_profile` | string | No | unset; exact Notarius ConfigKit profile selector |
| `pipeline.notarius.config_path` | string | Conditional | required when enabled; relative paths resolve from the pipeline file directory | | `pipeline.notarius.config_path` | string | Conditional | required when enabled; relative paths resolve from the pipeline file directory |
| `pipeline.notarius.pipeline_id` | string | Conditional | required when enabled | | `pipeline.notarius.pipeline_id` | string | Conditional | required when enabled |
@@ -383,6 +381,32 @@ Rules:
| `pipeline.scriptorium.artifact_families` | map | No | empty; expands one ordinary artifact per canonical party character | | `pipeline.scriptorium.artifact_families` | map | No | empty; expands one ordinary artifact per canonical party character |
| `pipeline.notification.mode` | string | No | `noop`; the only supported notification mode until a provider is implemented | | `pipeline.notification.mode` | string | No | `noop`; the only supported notification mode until a provider is implemented |
### Audita Selection and Credentials
`pipeline.audita.config_path` optionally passes an Audita v2 configuration file;
when empty, Audita uses its own native config discovery. `overlay`,
`proposal_profile`, and `validation_profile` are independent, optional Audita
selectors. Empty or omitted strings add no command-line override. Narratio's
selected pipeline overlay is never inferred as an Audita overlay, and Narratio
does not create or validate Audita's backend or PromptKit profile files. Prepare
them with [Audita's v2 migration guide](https://gitea.maximumdirect.net/eric/audita/src/tag/v2.0.0/docs/migrations/v2.md).
Omit `modules` or set it to `null` to use Audita's configured default sequence.
Set `modules: []` to run no correction modules. A nonempty list is passed in
order, including repetitions. Narratio does not add a reporting or debug flag;
Audita's external configuration controls those settings.
`pipeline.audita.credentials` lists secret-reference names, not values. Narratio
resolves every listed name during pipeline loading and forwards the captured
nonempty value under that exact name to Audita. It does not inspect Audita's
configuration to discover names or map them to aliases. Audita v2 resolves
credentials for **all configured backends**, even ones not selected by the
current profiles: list every named backend credential in the selected Audita
configuration. An unauthenticated backend needs no reference. Omission, `null`,
or `[]` forwards nothing. A Narratio overlay replaces the entire list, and
`[]` clears it. See the [Audita integration contract](./integrations/audita.md)
for the subprocess and redaction boundary.
### Notarius Configuration Profile ### Notarius Configuration Profile
`pipeline.notarius.config_profile` optionally selects a Notarius ConfigKit `pipeline.notarius.config_profile` optionally selects a Notarius ConfigKit
@@ -400,38 +424,39 @@ empty string or `default`, which explicitly select Notarius's composed base
configuration. Notarius owns selector interpretation and validation; Narratio configuration. Notarius owns selector interpretation and validation; Narratio
does not restrict profile names, resolve profile files, or rewrite the value. does not restrict profile names, resolve profile files, or rewrite the value.
This selection is independent of Narratio's own `--profile` selection. A This selection is independent of Narratio's own `--overlay` selection. A
Narratio overlay may explicitly select a differently named Notarius overlay, Narratio overlay may explicitly select a differently named Notarius overlay,
but Narratio never forwards its own profile name automatically. It is also but Narratio never forwards its own overlay name automatically. It is also
independent of `pipeline.notarius.llm_api_key`: an overlay may change either or independent of `pipeline.notarius.credentials`: an overlay may change either or
both fields according to the deployed Notarius configuration. See the both fields according to the deployed Notarius configuration. See the
[Notarius integration contract](./integrations/notarius.md) for invocation and [Notarius integration contract](./integrations/notarius.md) for invocation and
failure behavior. failure behavior.
### Notarius Credential ### Notarius Credentials
`pipeline.notarius.llm_api_key` optionally names the one environment variable `pipeline.notarius.credentials` optionally lists environment-variable names
to forward to the Notarius child process: to forward to the Notarius child process:
```yaml ```yaml
notarius: notarius:
llm_api_key: OPENROUTER_API_KEY credentials: [OPENROUTER_API_KEY, ANTHROPIC_API_KEY]
``` ```
The field contains the variable name, not a credential value. That name must The list contains variable names, not credential values. Those names must
match `api_key_env` in the Notarius/PromptKit profile selected by the deployed match the references used by the Notarius/PromptKit profiles that Notarius
Notarius pipeline; Narratio does not infer or remap provider names. Omission or loads. Notarius owns profile lookup; Narratio neither infers those names nor
`null` forwards nothing. A non-null selected reference must resolve at pipeline remaps them. Omission, `null`, or `[]` forwards nothing. Each selected reference
load time through the process environment or existing secrets-directory must resolve at pipeline load time through the process environment or existing
bootstrap, even when Notarius is disabled, extract is outside the requested secrets-directory bootstrap, even when Notarius is disabled, extract is outside
range, or a completed extraction can be reused. the requested range, or a completed extraction can be reused.
The Notarius child receives only Narratio's minimal execution environment plus The Notarius child receives only Narratio's minimal execution environment plus
this exact selected name and loaded value. Other credentials are not forwarded. these exact selected names and loaded values. Other credentials are not forwarded.
Changing the value, name, presence, or absence does not invalidate extract's Changing a value, name, presence, or absence does not invalidate extract's
semantic resume evidence. The public name remains part of safe effective semantic resume evidence. The public names remain part of safe effective
inspection, so renaming it may appear in `config diff` and change the effective inspection, so renaming them may appear in `config diff` and change the effective
configuration digest; rotating only its value does neither. configuration digest; rotating only their values does neither. An overlay
replaces the whole list, including with `[]` to clear it.
See the [Notarius integration contract](./integrations/notarius.md) for the See the [Notarius integration contract](./integrations/notarius.md) for the
delivery and redaction boundary. delivery and redaction boundary.

View File

@@ -10,6 +10,10 @@ polished transcripts and generated artifacts. Start with the
[Architecture](policy/architecture.md) for normative system boundaries, and the [Architecture](policy/architecture.md) for normative system boundaries, and the
[Internal Overview](internal/overview.md) for implemented component ownership. [Internal Overview](internal/overview.md) for implemented component ownership.
Agents must read [Agent Policy](policy/agents.md) before recommending, planning,
or implementing changes. It owns implementation discipline and the default
commit-after-completed-work rule; it does not authorize pushing or releasing.
## Go Prerequisite ## Go Prerequisite
Maintained development and verification require Go 1.26. Use the official Go Maintained development and verification require Go 1.26. Use the official Go
@@ -30,7 +34,7 @@ Maintained development and verification require Go 1.26. Use the official Go
| Adapters or external tool contracts | [Adapter Internals](internal/adapters.md) and [Integration Contracts](integrations/README.md) | The internal guide owns adapter composition and mechanics; integration documents own external formats and protocols. | | Adapters or external tool contracts | [Adapter Internals](internal/adapters.md) and [Integration Contracts](integrations/README.md) | The internal guide owns adapter composition and mechanics; integration documents own external formats and protocols. |
| Manifests, artifacts, workspace paths, or publish behavior | [Manifest Internals](internal/manifest.md), [Artifact Internals](internal/artifacts.md), [Workspace Internals](internal/workspace.md), [Publish Internals](internal/stage-publish.md), and [Operations](operations.md) | These separate implementation state and resolution from operator-visible layout and lifecycle. | | Manifests, artifacts, workspace paths, or publish behavior | [Manifest Internals](internal/manifest.md), [Artifact Internals](internal/artifacts.md), [Workspace Internals](internal/workspace.md), [Publish Internals](internal/stage-publish.md), and [Operations](operations.md) | These separate implementation state and resolution from operator-visible layout and lifecycle. |
| Maintained configuration or input examples | [Configuration](config.md) and [Examples](../examples/README.md) | The reference owns field meanings; the examples directory owns complete copyable files. | | Maintained configuration or input examples | [Configuration](config.md) and [Examples](../examples/README.md) | The reference owns field meanings; the examples directory owns complete copyable files. |
| Preparing, validating, or publishing a release | [Release Procedure](release.md) | The maintainer procedure owns version selection, candidate validation, guarded tag publication, and optional later CI inspection. | | Preparing, validating, or publishing a release | [Release Policy](policy/release.md) and [Release Procedure](release.md) | Policy owns requirements and exceptions; the procedure owns concrete validation, guarded publication, and optional later inspection. |
| Proposed or unimplemented behavior | `docs/roadmap/` | Future work belongs only in roadmap documentation until implemented. | | Proposed or unimplemented behavior | `docs/roadmap/` | Future work belongs only in roadmap documentation until implemented. |
For an existing subsystem, also inspect its focused tests and package-level For an existing subsystem, also inspect its focused tests and package-level

View File

@@ -1,69 +1,54 @@
# Integration: Audita # Integration: Audita
## Purpose Narratio invokes Audita v2's `process INPUT --glossary PATH --output PATH`
Define the Audita adapter contract used by the `polish` stage. subprocess for `polish`. The configured timeout and parent cancellation bound
execution. Narratio passes explicit `--config`, `--overlay`,
`--proposal-profile`, `--validation-profile`, `--transcript-description`,
`--output-schema`, and `--modules` only when selected. An omitted module list
leaves Audita's default sequence in place; `modules: []` passes an explicit
empty argument and runs no correction modules. Order and repetitions are kept.
Narratio passes no debug, work-directory, or reporting flags, leaving those
choices to Audita's own configuration.
## External Boundary Audita owns its ConfigKit file, backend and profile definitions, native config
discovery, and their validation. Narratio does not create an Audita
configuration or infer downstream overlay/profile names from its own selected
pipeline overlay. An empty Narratio Audita selector adds no CLI override.
The [configuration reference](../config.md#audita-selection-and-credentials)
owns Narratio's fields and defaults. Audita's
[v2 migration guide](https://gitea.maximumdirect.net/eric/audita/src/tag/v2.0.0/docs/migrations/v2.md)
owns its downstream file format.
Narratio invokes `audita process` as a subprocess for each polish operation. Each name in `pipeline.audita.credentials` is a ConfigKit secret reference
The configured timeout and parent cancellation bound the invocation. Internal resolved when Narratio loads the pipeline. Narratio forwards only the selected
runner composition is documented in names and their captured, nonempty values under those exact names, in the
[the adapter implementation guide](../internal/adapters.md). minimal child environment; it never maps them to a fixed alias or rereads the
parent environment. Every name is registered for captured stdout/stderr and
failure-diagnostic redaction. Audita resolves credentials for all configured
backends, including unselected ones, so operators must list every backend
credential that its selected configuration needs. The downstream files and
provider output remain Audita's responsibility, outside Narratio's
captured-stream redaction boundary.
## Request Contract The corrected transcript is the only canonical polish output. A successful
`PolishRequest` carries: invocation must produce a valid JSON transcript with a top-level `segments`
- required transcript/glossary/output/work-dir paths; array within Narratio's 64 MiB bound. Exit zero is accepted even if Audita's
- optional report path (required when report mode is enabled); ordinary reports describe recoverable model errors or no corrections. Narratio
- generated config and stdout/stderr log paths; does not parse report status, counts, or Markdown. It discovers only
- optional per-invocation module override. `errors.yml`, `recoveries.yml`, and `report.md` next to the requested output,
each subject to a 16 MiB read bound. Missing reports are allowed, for example
when Audita reporting is disabled externally. Available reports are diagnostic
references, not canonical artifact outputs. See Audita's
[ordinary output contract](https://gitea.maximumdirect.net/eric/audita/src/tag/v2.0.0/docs/integrations/output-files.md)
for their schemas, and [operations](../operations.md) for placement and
publication.
The constructed runner owns static Audita settings: binary, timeout, On nonzero exit, Narratio preserves the original subprocess error and
credentials, default modules, model and endpoint settings, validation and output available run-local evidence; it never promotes a transcript merely because
settings, report mode, and concurrency. The `polish` stage supplies only the file exists. The adapter returns safe paths, exit details, and selection
invocation-specific paths and may override modules for that invocation. metadata on failure. Narratio's `audita.generated.v2` YAML records the
invocation, including arguments, paths, and credential names but never values;
it is a diagnostic record, not a generated Audita config file.
## Result Contract Maintained Narratio examples: [full annotated pipeline](../../examples/pipeline.full.annotated.yml)
`PolishResult` returns: and [production-shaped pipeline](../../examples/pipeline.production.yml).
- processed transcript path;
- optional report path;
- work dir and generated-config/log paths;
- exit code, duration, binary provenance;
- adapter metadata map.
## Validation and Failure Semantics
Construction fails for invalid static config values, including:
- empty binary;
- non-positive timeout;
- invalid base URL;
- invalid output schema;
- invalid work-dir retention value;
- invalid concurrency values.
Run fails for:
- missing required request paths;
- subprocess execution failure;
- invalid processed transcript JSON (`segments` array required);
- invalid report JSON when reporting is enabled.
Processed transcript JSON is limited to 64 MiB and optional report JSON to 16
MiB. Both must be regular files without symlinked path components.
Failure results still include output/log/config/exit metadata for diagnostics.
## Deterministic Behavior
- CLI args are built from runner config + request in a fixed order.
- A configured typed `llm_api_key` reference is resolved during pipeline load;
the captured value is supplied only as the child's `AUDITA_LLM_API_KEY`
override and is never re-read from the parent environment.
- Generated invocation YAML (`audita.generated.v1`) is emitted when requested.
- Manifest writes are stage-owned; adapter itself is stateless.
## Configuration
Operator-selected values are defined under `pipeline.audita.*` in the
[configuration reference](../config.md#pipeline).
Maintained example with Audita config:
- [Full annotated pipeline](../../examples/pipeline.full.annotated.yml)
- [Production-shaped pipeline](../../examples/pipeline.production.yml)

View File

@@ -43,7 +43,7 @@ field acquire no additional version requirement. Omitted or null configuration
adds no flag. Supplied empty, `default`, and named selectors are forwarded adds no flag. Supplied empty, `default`, and named selectors are forwarded
without normalization so Notarius can apply its own ConfigKit semantics. This without normalization so Notarius can apply its own ConfigKit semantics. This
option selects a Notarius configuration overlay, not a PromptKit profile through option selects a Notarius configuration overlay, not a PromptKit profile through
`--llm-profile`, and Narratio never substitutes its own selected profile name. `--llm-profile`, and Narratio never substitutes its own selected overlay name.
A missing or invalid downstream overlay is an ordinary Notarius subprocess A missing or invalid downstream overlay is an ordinary Notarius subprocess
failure: Narratio does not retry without the selector or fall back to another failure: Narratio does not retry without the selector or fall back to another
profile. profile.
@@ -105,15 +105,16 @@ causes a cold miss. Chunk refresh bypasses lookup and publishes the accepted
replacement for the active source; it does not delete unrelated plans or replacement for the active source; it does not delete unrelated plans or
checkpoint state. checkpoint state.
When `pipeline.notarius.llm_api_key` is absent or null, Narratio adds no When `pipeline.notarius.credentials` is absent, null, or empty, Narratio adds no
credential to that environment. When configured, the field names an environment credentials to that environment. When configured, each list entry names an
variable whose already-loaded nonempty value is forwarded under that exact environment variable whose already-loaded nonempty value is forwarded under
name. Operators must use the same name as the `api_key_env` in the selected that exact name. Operators must use the names referenced by the selected
Notarius/PromptKit profile. Narratio does not inspect the Notarius configuration Notarius/PromptKit providers. Narratio does not inspect the Notarius configuration
to infer a provider or destination name, and it does not forward unrelated to infer providers or destination names, and it does not forward unrelated
credentials from its parent environment or secrets directory. credentials from its parent environment or secrets directory. A Narratio
overlay replaces the whole credential list; `[]` clears it.
The selected name is registered with Narratio's shared streaming redactor. Every selected name is registered with Narratio's shared streaming redactor.
Credential bytes written by the child to captured stdout, captured stderr, or Credential bytes written by the child to captured stdout, captured stderr, or
stderr-derived failure diagnostics are replaced with `<redacted>`, including stderr-derived failure diagnostics are replaced with `<redacted>`, including
custom names not known to the built-in sensitive-name list. Narratio does not custom names not known to the built-in sensitive-name list. Narratio does not

View File

@@ -68,11 +68,15 @@ owner of serializing them as repeated `--reference` arguments before `--json`.
It also serializes an effective resume request as `--resume` and a nonempty It also serializes an effective resume request as `--resume` and a nonempty
validated chunk mode as `--chunk_cache <mode>`. The extract stage, not the validated chunk mode as `--chunk_cache <mode>`. The extract stage, not the
adapter, resolves force precedence before constructing the request. adapter, resolves force precedence before constructing the request.
Its request may also carry one already-resolved opaque ConfigKit secret Its request may also carry already-resolved ConfigKit secret references.
reference. Only the Notarius adapter reads that value, rejects an unresolved or Audita's request carries the same kind of list. Both adapters use the shared
empty programmatic reference, and maps the exact configured name/value into the subprocess helper to convert their selected references into exact-name child
shared subprocess override and sensitive-name fields. It never rereads the environment overrides and sensitive-name registration. That helper rejects
parent environment. A nil reference preserves the previous invocation. unresolved or empty programmatic references, but neither adapter rereads the
parent environment or inspects downstream configuration to discover names.
Empty lists add no credential overrides. See the public [Audita](../integrations/audita.md)
and [Notarius](../integrations/notarius.md) contracts for selection and
downstream-file boundaries.
Application-owned object-store construction loads configured filesystem Application-owned object-store construction loads configured filesystem
secrets before invoking the invocation's storage factory. Production commands secrets before invoking the invocation's storage factory. Production commands

View File

@@ -9,9 +9,9 @@ pipeline-loading boundary implemented by `internal/config`.
`LoadPipeline` assembles and validates a pipeline in this order: `LoadPipeline` assembles and validates a pipeline in this order:
1. Give ConfigKit a fresh typed `PipelineConfig` default value, the root file, 1. Give ConfigKit a fresh typed `PipelineConfig` default value, the root file,
enabled imports, and the caller's profile selection. Omitted, empty, and enabled imports, and the caller's overlay selection. Omitted, empty, and
exact `default` selections use the base; named profiles use the fixed exact `default` selections use the base; named overlays use the fixed
`profiles/<name>.yml` convention. `overlays/<name>.yml` convention.
2. ConfigKit parses the root and declared imports, additively merges base 2. ConfigKit parses the root and declared imports, additively merges base
sources, applies only the selected overlay, and strictly decodes the result. sources, applies only the selected overlay, and strictly decodes the result.
3. The definition resolver applies recorded entry-level and inherited defaults, 3. The definition resolver applies recorded entry-level and inherited defaults,
@@ -45,7 +45,7 @@ a temporary downloaded session file therefore cannot invalidate the resolved
pipeline or campaign context. pipeline or campaign context.
Campaign and session files use independent ConfigKit definitions with imports Campaign and session files use independent ConfigKit definitions with imports
and profiles disabled. Campaign files normally load directly from their source; and overlays disabled. Campaign files normally load directly from their source;
session files are first read through the 8 MiB bounded-read boundary because the session files are first read through the 8 MiB bounded-read boundary because the
application must reject unresolved template placeholders before passing an exact application must reject unresolved template placeholders before passing an exact
byte snapshot to ConfigKit. Local and remotely downloaded session bytes then use byte snapshot to ConfigKit. Local and remotely downloaded session bytes then use
@@ -53,8 +53,9 @@ the same typed loader and retain the existing post-load identity expectations,
stable-input precedence, and source-relative path semantics. stable-input precedence, and source-relative path semantics.
The application also has a separate read-only inspection resolver for `config The application also has a separate read-only inspection resolver for `config
validate`, `config show`, `config sources`, and `config artifacts`. It uses the same production root/profile and validate`, `config show`, `config sources`, and `config artifacts`. It uses the
campaign selection functions, but never routes through session discovery, same production root, overlay, and campaign selection functions, but never routes
through session discovery,
remote-session download, adapter composition, workspace remote-session download, adapter composition, workspace
initialization, manifest access, or cleanup. A pipeline with retained artifact initialization, manifest access, or cleanup. A pipeline with retained artifact
family declarations must resolve its selected campaign before ordinary pipeline family declarations must resolve its selected campaign before ordinary pipeline
@@ -73,7 +74,7 @@ commands do not marshal runtime objects directly.
`EffectivePipelineSources` and `EffectiveCampaignSources` provide the separate `EffectivePipelineSources` and `EffectiveCampaignSources` provide the separate
safe provenance projection for `config sources`. Pipeline ownership begins with safe provenance projection for `config sources`. Pipeline ownership begins with
the complete logical field paths projected from the schema and classifies the complete logical field paths projected from the schema and classifies
each contributor as root, import, profile, or centralized default. The each contributor as root, import, overlay, or centralized default. The
projection replaces generated concrete member paths with paired family and projection replaces generated concrete member paths with paired family and
canonical-party records, and does the same for generated publish rules. canonical-party records, and does the same for generated publish rules.
Campaign records identify campaign-owned fields and party inputs; canonical Campaign records identify campaign-owned fields and party inputs; canonical
@@ -106,7 +107,7 @@ configured roster authority; player and session-party fields are unsupported.
## Canonical Party Domain ## Canonical Party Domain
`ParseParty` is the package-owned boundary for parsing a party source. Its `ParseParty` is the package-owned boundary for parsing a party source. Its
single-source ConfigKit definition disables imports and profiles, requires single-source ConfigKit definition disables imports and overlays, requires
`schema_version` through `VersionRule`, and strictly decodes the `schema_version` through `VersionRule`, and strictly decodes the
character-keyed typed schema before applying Narratio's party-domain checks. character-keyed typed schema before applying Narratio's party-domain checks.
Successful metadata coordinates recover authored character-map order without a Successful metadata coordinates recover authored character-map order without a
@@ -144,14 +145,14 @@ not compatibility contracts.
## Diagnostics And Runtime Metadata ## Diagnostics And Runtime Metadata
Syntax, duplicate-key, merge, profile, and schema failures include the Syntax, duplicate-key, merge, overlay, and schema failures include the
relevant source name and full field path. Additive conflicts report every relevant source name and full field path. Additive conflicts report every
claiming source so operators can repair the split without repeatedly claiming source so operators can repair the split without repeatedly
rediscovering additional conflicts. rediscovering additional conflicts.
The loaded pipeline retains private runtime metadata for the absolute root The loaded pipeline retains private runtime metadata for the absolute root
path, ordered imports, selected profile name and selection source, selected path, ordered imports, selected overlay name, source, and path, original
overlay, original ConfigKit metadata and source snapshots, effective digest, ConfigKit metadata and source snapshots, effective digest,
and leaf ownership. Base and leaf ownership. Base
leaves retain their root/import owners, replaced leaves belong to the selected leaves retain their root/import owners, replaced leaves belong to the selected
overlay, and centrally supplied values use the synthetic `default` owner. This overlay, and centrally supplied values use the synthetic `default` owner. This
@@ -163,7 +164,7 @@ the same typed safe projection used by show and diff. Runtime Notarius paths rem
execution, but the digest substitutes their normalized logical values captured execution, but the digest substitutes their normalized logical values captured
before root-relative resolution, so relocating an equivalent configuration before root-relative resolution, so relocating an equivalent configuration
bundle does not change provenance. Because ConfigKit and resolution metadata bundle does not change provenance. Because ConfigKit and resolution metadata
are private, the digest excludes source layout, profile name, and ownership. are private, the digest excludes source layout, overlay name, and ownership.
Configuration stores credentials as ConfigKit typed references. A successful Configuration stores credentials as ConfigKit typed references. A successful
load resolves their values inside the opaque typed boundary, while this safe load resolves their values inside the opaque typed boundary, while this safe
projection serializes only `EnvName()` identities. Credential-value changes are projection serializes only `EnvName()` identities. Credential-value changes are
@@ -177,7 +178,7 @@ for later runtime expansion.
## Test Surfaces ## Test Surfaces
`pipeline_configkit_test.go` exercises real imports and fixed-path profiles, `pipeline_configkit_test.go` exercises real imports and fixed-path overlays,
base selection, unselected-overlay isolation, source attribution, and Narratio's base selection, unselected-overlay isolation, source attribution, and Narratio's
unique artifact/family base-declaration rule. Existing focused configuration unique artifact/family base-declaration rule. Existing focused configuration
tests protect defaults, explicit-value semantics, strict decoding, validation, tests protect defaults, explicit-value semantics, strict decoding, validation,

View File

@@ -23,9 +23,11 @@ portable opaque segments. Unsafe legacy identities are rejected with migration
guidance rather than being normalized into a different workspace or remote guidance rather than being normalized into a different workspace or remote
namespace. namespace.
Decoding is strict at every typed manifest field. Unknown fields are rejected; Decoding rejects unknown typed fields, including informational fields inside
the schema version remains `narratio.session-manifest.v1` and there is no `effective_config` and its nested selection. The schema version remains
compatibility reader that silently drops retired state. Cleanup progress uses `narratio.session-manifest.v1`; there is no compatibility reader that silently
drops retired fields. See [overlay migration](../operations.md#migrating-manifest-overlay-provenance)
for deliberate migration of retired selection provenance. Cleanup progress uses
only the cleanup entry in `stages`. only the cleanup entry in `stages`.
Every persisted session manifest has a non-nil `stages` map. Each entry is Every persisted session manifest has a non-nil `stages` map. Each entry is
@@ -193,6 +195,25 @@ establish a current immutable snapshot.
- writes through a sibling temporary file and atomic replacement visibility; - writes through a sibling temporary file and atomic replacement visibility;
- updates `updated_at` on save. - updates `updated_at` on save.
### Checkpoint persistence boundary
Analyze and transcribe share one private checkpoint operation in
`internal/stage`. Their typed callers still decide when to checkpoint, validate
their collections, populate stage-owned fields, and serialize access. The
shared operation copies the manifest and its checkpoint-relevant mutable
collections, applies the typed update to the copied target record, and calls
the existing `manifest.Store` exactly once. Only after that save succeeds does
it promote the saved target record and manifest `updated_at` into live state;
it preserves an existing target record's identity and leaves unrelated live
stage records in place.
The copy boundary includes stage records, input and artifact slices, aggregate
output/log/configuration slices, and the typed analyze and transcribe
collections that callbacks or `LocalStore.Save` may modify. Metadata and other
pointer fields remain shared read-only because neither checkpoint callback nor
the store mutates them. This is a bounded execution helper, not a general
manifest clone or a transaction across transcript/artifact files.
Manifest replacement provides atomic visibility, not a crash- or power-loss Manifest replacement provides atomic visibility, not a crash- or power-loss
durability guarantee. Callers reload after a returned save error before retrying. durability guarantee. Callers reload after a returned save error before retrying.
A transcribe or analyze checkpoint error leaves the prior manifest collection A transcribe or analyze checkpoint error leaves the prior manifest collection
@@ -287,10 +308,10 @@ after such a private content change.
The session manifest is the authoritative stage-progress ledger across The session manifest is the authoritative stage-progress ledger across
invocations. It retains the most recently resolved invocation's bounded invocations. It retains the most recently resolved invocation's bounded
configuration provenance. It identifies the selected profile name and source configuration provenance. It identifies the selected overlay name and source
(`default` or `cli`) plus the effective configuration digest, but never a raw (`explicit` when selected) plus the effective configuration digest, but never a raw
secret or profile content. This provenance is informational: it does not secret or overlay content. This provenance is informational: it does not
participate in stage resume or cache decisions. A profile change therefore participate in stage resume or cache decisions. An overlay change therefore
invalidates only stages whose semantic configuration changed. When a private invalidates only stages whose semantic configuration changed. When a private
external-tool model, module, prompt, or profile changes behind an unchanged external-tool model, module, prompt, or profile changes behind an unchanged
configured identifier, use `--force` for the affected work. configured identifier, use `--force` for the affected work.

View File

@@ -37,7 +37,7 @@ failed stage or required manifest save prevents later stages from starting.
| --- | --- | --- | | --- | --- | --- |
| Executable | `cmd/narratio` | Process entry, standard stream wiring, argument handoff, and exit status. | | Executable | `cmd/narratio` | Process entry, standard stream wiring, argument handoff, and exit status. |
| Application orchestration | `internal/app` | Command dispatch, configuration selection, secret-file environment loading, production composition, session locking, planning, execution, restore, and user-facing reporting. | | Application orchestration | `internal/app` | Command dispatch, configuration selection, secret-file environment loading, production composition, session locking, planning, execution, restore, and user-facing reporting. |
| Configuration | [`internal/config`](configuration.md) | ConfigKit-backed pipeline imports and profiles, canonical party and family expansion, strict YAML loading, defaults, normalization, session templating, and validation. | | Configuration | [`internal/config`](configuration.md) | ConfigKit-backed pipeline imports and overlays, canonical party and family expansion, strict YAML loading, defaults, normalization, session templating, and validation. |
| Pipeline stages | `internal/stage` | Canonical stage registry, shared stage contract, execution dependencies, and implemented stage behavior. | | Pipeline stages | `internal/stage` | Canonical stage registry, shared stage contract, execution dependencies, and implemented stage behavior. |
| External boundaries | `internal/adapters`, `internal/audio` | WhisperX HTTP, downstream subprocesses, notification, object storage, and S3 audio materialization behind Narratio contracts. | | External boundaries | `internal/adapters`, `internal/audio` | WhisperX HTTP, downstream subprocesses, notification, object storage, and S3 audio materialization behind Narratio contracts. |
| Manifests | `internal/manifest` | Durable session progress, stage transitions, validation, and atomic persistence. | | Manifests | `internal/manifest` | Durable session progress, stage transitions, validation, and atomic persistence. |
@@ -106,7 +106,7 @@ so any earlier replacement can stale a prior cleanup result.
## Focused Documentation ## Focused Documentation
- [Configuration Internals](configuration.md): pipeline imports and profiles, - [Configuration Internals](configuration.md): pipeline imports and overlays,
field ownership, decoding, and root-relative path semantics. field ownership, decoding, and root-relative path semantics.
- [Adapter Internals](adapters.md): external adapter boundaries, composition, - [Adapter Internals](adapters.md): external adapter boundaries, composition,
failure behavior, and test surfaces. failure behavior, and test surfaces.

View File

@@ -115,7 +115,11 @@ Supported source families:
- before the first adapter call, checkpoints the reconciled starting collection - before the first adapter call, checkpoints the reconciled starting collection
when it removed configuration records or cleared obsolete authority. After when it removed configuration records or cleared obsolete authority. After
each successful artifact, checkpoints the complete collection before making each successful artifact, checkpoints the complete collection before making
that artifact available to the next scheduled dependent. that artifact available to the next scheduled dependent. Analyze supplies
its typed update to the shared
[checkpoint persistence boundary](manifest.md#checkpoint-persistence-boundary)
and refreshes its working and committed collections only after the save
succeeds.
- keeps adapter output in the invocation's run-local analyze directory until - keeps adapter output in the invocation's run-local analyze directory until
it is a safe, non-empty, bounded regular file with a calculated checksum and it is a safe, non-empty, bounded regular file with a calculated checksum and
complete output contract. Canonical replacement uses the shared atomic file complete output contract. Canonical replacement uses the shared atomic file

View File

@@ -12,37 +12,41 @@ Run Audita polishing on base transcript and produce polished transcript.
## Outputs ## Outputs
- `transcripts/polished.json` - `transcripts/polished.json`
- optional `artifacts/audita.report.json`
The transcript is the only canonical output. Available `errors.yml`,
`recoveries.yml`, and `report.md` remain beside the run-local transcript and
are recorded as diagnostics, not artifact outputs.
## Key Behavior ## Key Behavior
- resolves base transcript only from verified merge manifest output evidence. - resolves base transcript only from verified merge manifest output evidence.
- invokes an Audita runner configured with static model/runtime options; the - invokes an Audita v2 runner with external configuration selectors and
invocation supplies paths and modules. explicitly forwarded provider credentials; the invocation supplies paths.
- validates processed transcript structure (`segments` array required). - validates processed transcript structure (`segments` array required).
- validates optional report JSON. - validates reported diagnostic paths against the three fixed adjacent names.
- materializes canonical outputs; records logs/generated config and adapter metadata. - materializes only the canonical transcript; records available reports with
stdout/stderr logs, generated invocation, and safe adapter metadata.
## Invariants ## Invariants
- polished transcript schema validation is mandatory. - polished transcript schema validation is mandatory.
- report output is config-gated. - reports are optional diagnostics; Audita's external configuration may disable
them. A failed invocation never promotes an incidental transcript.
## Resume Semantics ## Resume Semantics
The versioned semantic fingerprint covers the Audita service endpoint, model, Version 2 semantic evidence covers Audita's config path, downstream overlay,
validation model, module set, transcript description, output schema, selected proposal and validation profile selectors, ordered module selection (including
external configuration path, and canonical polished-transcript identity. Module the distinction between omission and an explicit empty list), transcript
ordering is normalized because the configured modules form a set. Audita's description, output schema, and canonical polished-transcript identity.
executable, timeouts, concurrency, report and debug behavior, work retention, Credentials, executable path, timeout, and diagnostics are operational and do
and resolved credential value are operational and do not invalidate a not invalidate a successful result. Public credential reference names may
successful result. The public credential reference name may participate in participate in configuration provenance but never expose resolved values.
configuration provenance but never exposes its resolved value.
Narratio can fingerprint a selected model, module, or configuration identifier, Narratio fingerprints selections, not the contents of Audita-owned config or
but it cannot inspect content that Audita privately resolves behind that stable profiles. Force `polish` after changing those files behind unchanged selections.
identifier. Force `polish` after changing such private content without changing When polish is selected, older semantic evidence is reconsidered and the stage
its identifier. reruns; a downstream-only invocation does not eagerly run polish.
## Related Contracts And Tests ## Related Contracts And Tests

View File

@@ -35,9 +35,10 @@ Generate raw per-speaker transcripts from prepared audio using WhisperX.
- output path returned by adapter must match requested output path. - output path returned by adapter must match requested output path.
- an empty adapter result path means the requested path; adapters cannot select - an empty adapter result path means the requested path; adapters cannot select
an alternate destination. an alternate destination.
- candidate collection construction, manifest save, and installation into live - candidate collection construction, the shared
state are serialized. Expensive hashing and HTTP work remain outside that [checkpoint persistence boundary](manifest.md#checkpoint-persistence-boundary),
critical section. and installation into live state are serialized by transcribe's mutex.
Expensive hashing and HTTP work remain outside that critical section.
- a canonical file has no completion authority until its manifest checkpoint - a canonical file has no completion authority until its manifest checkpoint
succeeds. A save failure preserves the last successfully committed succeeds. A save failure preserves the last successfully committed
collection for ordinary retry. collection for ordinary retry.

View File

@@ -70,19 +70,19 @@ narratio run 2026-04-04
narratio session status 2026-04-04 narratio session status 2026-04-04
``` ```
Run, plan, and status output identify the resolved pipeline profile (or `none`) Run, plan, and status output identify the resolved pipeline overlay (or `none`)
and effective configuration digest. Status distinguishes the current resolved and effective configuration digest. Status distinguishes the current resolved
value from the last value persisted in the session manifest, which helps value from the last value persisted in the session manifest, which helps
diagnose profile switches without changing resume authority. diagnose overlay switches without changing resume authority.
Before switching an operational profile, compare its effective meaning with the Before switching an operational overlay, compare its effective meaning with the
production base through `narratio config diff default <profile>`. production base through `narratio config diff default <overlay>`.
The command is read-only and succeeds whether it finds differences or not. Its The command is read-only and succeeds whether it finds differences or not. Its
sorted records describe defaulted, expanded concrete configuration—not source sorted records describe defaulted, expanded concrete configuration—not source
file layout—so it can be used to review model, artifact, and publish changes file layout—so it can be used to review model, artifact, and publish changes
without creating a session or run. Use `narratio config artifacts` to review the without creating a session or run. Use `narratio config artifacts` to review the
concrete artifact identities, definitions, outputs, and dependencies. Select the concrete artifact identities, definitions, outputs, and dependencies. Select the
same campaign explicitly when profiles could resolve different campaign paths; same campaign explicitly when overlays could resolve different campaign paths;
see the [CLI reference](cli.md#config-validate-config-show-config-sources-config-artifacts-and-config-diff) see the [CLI reference](cli.md#config-validate-config-show-config-sources-config-artifacts-and-config-diff)
for syntax and record format. for syntax and record format.
@@ -124,10 +124,11 @@ membership, S3 object identity, or missing/tampered copies rerun prepare and
its fixed descendants without requiring `--force`. Changing prepare selection its fixed descendants without requiring `--force`. Changing prepare selection
semantics likewise reruns all fixed descendants; changing semantics likewise reruns all fixed descendants; changing
WhisperX language/service identity reuses prepare; changing a Seriatim merge WhisperX language/service identity reuses prepare; changing a Seriatim merge
transformation reuses prepare and transcribe; and changing an Audita model transformation reuses prepare and transcribe; and changing a selected Audita
reuses prepare, transcribe, and merge while rebuilding transcript refinement. overlay, profile, or module sequence reuses prepare, transcribe, and merge while
A trim change invalidates both render and extract through the fixed dependency rebuilding transcript refinement. A trim change invalidates both render and
relation, while a render-only change preserves the extract sibling. extract through the fixed dependency relation, while a render-only change
preserves the extract sibling.
Operational timeouts, retry/concurrency tuning, executable paths, Operational timeouts, retry/concurrency tuning, executable paths,
workspace/cache/spool placement, reports, diagnostics, and secret values are workspace/cache/spool placement, reports, diagnostics, and secret values are
@@ -284,17 +285,17 @@ intends to replace otherwise-current artifacts.
### Developing With A Notarius Configuration Profile ### Developing With A Notarius Configuration Profile
A Narratio development overlay can explicitly select a Notarius overlay without A Narratio development overlay can explicitly select a Notarius overlay without
requiring the names to match. For example, `profiles/testing.yml` may contain: requiring the names to match. For example, `overlays/testing.yml` may contain:
```yaml ```yaml
notarius: notarius:
config_profile: downstream-economy config_profile: downstream-economy
``` ```
Selecting Narratio's `testing` profile then supplies `downstream-economy` only Selecting Narratio's `testing` overlay then supplies `downstream-economy` only
when extraction executes. Switching that explicit selector makes a recorded when extraction executes. Switching that explicit selector makes a recorded
extraction non-current and reruns it when `extract` is in the selected stage extraction non-current and reruns it when `extract` is in the selected stage
range; the usual dependent invalidation then applies. Selecting a profile does range; the usual dependent invalidation then applies. Selecting an overlay does
not create a separate workspace or retain a separate current extraction result. not create a separate workspace or retain a separate current extraction result.
Narratio cannot observe edits inside Notarius configuration behind an unchanged Narratio cannot observe edits inside Notarius configuration behind an unchanged
@@ -409,6 +410,82 @@ execute. Deleting Narratio's local reference snapshots does not invalidate a
complete durable extraction; missing snapshots are reconstructed only when a complete durable extraction; missing snapshots are reconstructed only when a
later extraction actually runs. later extraction actually runs.
## Migrating Manifest Overlay Provenance
The pipeline-selection rename is a clean cutover. Manifests containing
`effective_config.selected_profile` are rejected by strict decoding; Narratio
does not silently discard or translate that retired field.
Before using an affected local session with the new version:
1. Stop Narratio activity for the session and back up its manifest.
2. Rename only `effective_config.selected_profile` to `selected_overlay`, keeping
its `name` and `source`, or remove the retired informational member. If a
current `selected_overlay` member already exists, retain it and remove the
retired member rather than creating duplicate keys.
3. Preserve the schema version, digest, stage records, checkpoint evidence,
output references, and other session state. Retry the intended command.
This metadata is informational, not resume authority. Do not delete session
progress or force all stages merely to perform this migration. Other unknown
fields still require investigation rather than blanket removal.
Do not edit immutable remote committed snapshots. Restoring an older snapshot
with retired provenance requires a compatible previous Narratio version, followed
by migration of the restored local manifest before using the new version.
## Migrating Audita and Provider Credentials
This is a breaking clean cutover to Audita v2. Narratio does not translate an
Audita v1 configuration, retain old field aliases, or generate a downstream
configuration. Update both the deployed Audita executable/configuration and
the Narratio pipeline before running polish. Retired Narratio fields are
rejected by strict configuration loading; account for this break when choosing
a release version.
| Previous Narratio setting | New ownership and selection |
| --- | --- |
| `audita.base_url` | Audita v2 `backends.<id>.endpoint` |
| `audita.total_llm_concurrency`, `proposal_llm_concurrency`, `validation_llm_concurrency` | Audita v2 `backends.<id>.concurrency` and optional `queue_capacity`; backend capacity is shared across roles |
| `audita.model`, `validation_model` | Audita PromptKit profile files; optionally select them from Narratio with `audita.proposal_profile` and `validation_profile` |
| `audita.llm_api_key` | `audita.credentials: [PROVIDER_KEY_NAME]`, matching each Audita backend's `credential` name |
| `notarius.llm_api_key` | `notarius.credentials: [PROVIDER_KEY_NAME]`, matching references in Notarius-owned profiles |
| `audita.work_dir_retention`, `report` | Remove; Audita's external configuration owns diagnostics and reporting |
An Audita configuration can also be selected through `audita.config_path`,
and `audita.overlay` selects an Audita overlay independently of Narratio's
`--overlay`. Narratio forwards no implicit provider key: a single provider-named
secret source may be listed for both adapters, and an Audita-only backend key
may be listed only for Audita. Audita resolves credentials for all configured
backends, including those not currently selected. Notarius looks up its own
profiles; Narratio does not discover their credential names. Credential lists
may be cleared with `[]` in a Narratio overlay.
Prepare the external file from Audita's maintained
[local example](https://gitea.maximumdirect.net/eric/audita/src/tag/v2.0.0/examples/minimal-config.yml),
[service example](https://gitea.maximumdirect.net/eric/audita/src/tag/v2.0.0/examples/production-config.yml),
and [v2 migration guide](https://gitea.maximumdirect.net/eric/audita/src/tag/v2.0.0/docs/migrations/v2.md).
Before switching the executable, validate the file offline:
```bash
audita config validate --config /usr/local/etc/audita/config.yml
```
Use `audita config print-effective --config /usr/local/etc/audita/config.yml --view profiles`
to inspect downstream profile selection without contacting a provider. For a
production Audita configuration, leave ordinary reports enabled
and debug disabled unless an operator deliberately chooses otherwise; Narratio
does not override those settings. Audita writes `errors.yml`, `recoveries.yml`,
and `report.md` beside the polished output when reporting is enabled. An
exit-zero run with a valid transcript succeeds even if those reports describe
recoverable errors or no applied corrections. See the [Audita integration
contract](./integrations/audita.md) for report placement and limits.
Narratio's polish resume evidence tracks selected config path, Audita overlay,
profiles, ordered modules, description, schema, and output identity. Editing
Audita-owned files behind unchanged selectors is invisible to Narratio; force
polish with `narratio run-stage polish <session-id> --force` after such edits.
## External Command Lifecycle ## External Command Lifecycle
When an external command is cancelled or times out, Narratio terminates its When an external command is cancelled or times out, Narratio terminates its
@@ -426,6 +503,9 @@ tree and reports which stream exceeded the limit.
Run-local diagnostics are: Run-local diagnostics are:
- `runs/{run_id}/polish/outputs/transcripts/errors.yml`,
`recoveries.yml`, and `report.md` when Audita writes them beside its
run-local polished transcript
- `runs/{run_id}/extract/notarius.receipt.json` - `runs/{run_id}/extract/notarius.receipt.json`
- `runs/{run_id}/extract/notarius.stderr.log` - `runs/{run_id}/extract/notarius.stderr.log`
- `runs/{run_id}/extract/notarius-output/` before durable promotion - `runs/{run_id}/extract/notarius-output/` before durable promotion
@@ -439,6 +519,10 @@ Unlisted files and unsafe entries are never uploaded; a run with no declared
current-run diagnostics uploads no run-local files. No distinguished diagnostic current-run diagnostics uploads no run-local files. No distinguished diagnostic
file is uploaded. The durable bundle is never scanned for implicit publication; file is uploaded. The durable bundle is never scanned for implicit publication;
only lanes named by explicit `pipeline.publish.outputs` rules are uploaded. only lanes named by explicit `pipeline.publish.outputs` rules are uploaded.
To inspect a published polish report remotely, read its declared object under
the run archive's `polish/outputs/transcripts/` prefix. Session restore does
not restore run-archive diagnostics as canonical session files; it restores only
the committed manifest and declared transcript/artifact objects.
To intentionally replace the current extraction result, run: To intentionally replace the current extraction result, run:
@@ -692,9 +776,10 @@ files. Existing environment variables—including empty values—always win.
S3 `access_key_id` and `secret_access_key` are an optional pair of typed S3 `access_key_id` and `secret_access_key` are an optional pair of typed
environment references. When both are absent, the AWS SDK retains its default environment references. When both are absent, the AWS SDK retains its default
credential provider chain. When both are configured, Narratio supplies their credential provider chain. When both are configured, Narratio supplies their
load-time resolved values through an explicit static provider. Audita's optional load-time resolved values through an explicit static provider. Audita and
`llm_api_key` is likewise captured at pipeline load and supplied only through Notarius credential lists likewise resolve at pipeline load. Each adapter
the child process's `AUDITA_LLM_API_KEY` override. receives only its listed names and captured values, with no alias mapping or
ambient environment inheritance. See [configuration](./config.md#audita-selection-and-credentials).
External adapter results are individually bounded before Narratio validates or External adapter results are individually bounded before Narratio validates or
materializes them. These per-file limits do not reserve disk space: prevent hard materializes them. These per-file limits do not reserve disk space: prevent hard

95
docs/policy/agents.md Normal file
View File

@@ -0,0 +1,95 @@
# Agent Policy
**Base Policy Version:** 1.1
**Last Updated**: 2026-09-25
## Purpose
Agents working in this repository must read and adhere to the following house rules.
## Implementation Discipline
**KEY PRINCIPLES:** Write the simplest idiomatic code that satisfies the user's
request. Do not implicitly strengthen requirements, restrictions, or guarantees
beyond what the user actually requested.
Simplify the mechanism, not the user's choices.
**Keep implementation machinery proportionate.** Use straightforward,
idiomatic code and introduce only the machinery needed to support the requested
behavior and flexibility. Optimize for conceptual simplicity and
maintainability, not for the fewest lines, fewest options, or narrowest product
surface.
**Do not invent restrictions.** Do not reject, prohibit, constrain, cap,
harden, or otherwise narrow behavior unless required by the user, an explicit
repository contract, or an unavoidable correctness constraint. Preserve
operator and caller choice where policy has not been established. If an
additional restriction appears advisable, present it as a decision rather than
silently implementing it.
A correctness constraint must follow from the requested behavior or an
established invariant, not from the convenience of the chosen implementation.
Explain the specific failure it prevents and why a less restrictive
implementation cannot satisfy the contract.
**Do not invent guarantees.** Do not strengthen public contracts, guarantees,
or invariants beyond those expressly requested by the user.
**Use the standard library.** For example: in almost every case, the best
approach to copying files is to use the standard library. Writing custom code to
implement power-loss protection at the application level, or to guard against
bad actors with privileged and concurrent access to the host's filesystem,
is wasteful, unnecessary, and not idiomatic. Stick to the simple, standard, and
idiomatic approach unless another path is expressly requested by the user.
**An implementation detail is not repository policy.** Tests and documentation
must not elevate incidental behavior into a durable guarantee or restriction
unless that behavior was expressly selected as part of the contract. Existing
explicit contracts remain authoritative; changing or weakening one requires a
deliberate decision rather than being inferred from this principle.
Agent-authored plans, tests, documentation, and prior implementations are not
evidence that an additional restriction was deliberately approved. Identify the
authorizing requirement or decision; when that authority is unclear, surface
the ambiguity rather than treating repetition as approval.
Standard-library guidance does not authorize weakening Narratio's established
filesystem, manifest, or publication contracts. Preserve them unless a deliberate
decision changes them.
## Git Commit Policy
By default, create a commit after completing each coherent unit of work, using a
concise, plain-English message describing what changed. This policy is standing
authorization to create those local commits; a separate user request is not
required. An explicit user instruction to leave work uncommitted takes precedence.
A unit of work is a focused, reviewable outcome, including its relevant tests and
documentation. Do not commit after every intermediate edit or create empty commits.
Complete the appropriate validation before committing. If work is incomplete or
validation is blocked, report that state rather than presenting it as completed.
Before committing:
1. Run `git status --short` and review the relevant diff, including any staged
changes. Identify changes that predate the current unit of work.
2. Exclude secrets, local environment files, generated junk, and unrelated changes.
3. Stage only the files or hunks belonging to the completed unit. Use `git add .`
only when every included change belongs to that unit. Do not disturb unrelated
staged or unstaged work.
4. Review `git diff --staged` and run appropriate checks for the change. Do not
repeat checks already passed for unchanged content merely to create a commit.
5. Review `git log --oneline -n 10` and use
`git commit -m "<concise plain-English commit message>"`.
6. Report the commit identifier and any remaining uncommitted work.
If the unit cannot be safely separated from pre-existing work, leave it uncommitted
and explain the overlap rather than silently including that work. If a commit
fails, preserve the changes and report the failure; do not bypass hooks.
Default commit authorization does not authorize pushing, publishing, amending,
resetting, reverting, or rewriting history. Those actions require a separate user
instruction. Do not use `git commit -a` or `git commit --no-verify` to bypass the
staging and validation discipline above.

View File

@@ -1,5 +1,9 @@
# Architecture # Architecture
**Base Policy Version:** 1.0
**Last Updated**: 2026-09-25
This document defines Narratio's intended high-level architecture and the This document defines Narratio's intended high-level architecture and the
invariants that changes must preserve. Implemented component details belong in invariants that changes must preserve. Implemented component details belong in
the [Internal Overview](../internal/overview.md) and its linked documents. the [Internal Overview](../internal/overview.md) and its linked documents.
@@ -148,13 +152,13 @@ Configuration is strict, explicit, centralized, and operator-oriented.
- Empty configured values do not silently replace meaningful defaults. - Empty configured values do not silently replace meaningful defaults.
- Validation rejects invalid configuration before stage execution where - Validation rejects invalid configuration before stage execution where
practical. practical.
- Root-owned imports and one selected profile resolve deterministically through - Root-owned imports and one selected overlay resolve deterministically through
the configuration owner; commands do not implement their own merge rules. the configuration owner; commands do not implement their own merge rules.
- Canonical party rosters are campaign-owned. Their derived players projection - Canonical party rosters are campaign-owned. Their derived players projection
and concrete character-family artifacts are resolved before runtime stages and concrete character-family artifacts are resolved before runtime stages
or adapters receive configuration. or adapters receive configuration.
- Resume uses stage- or artifact-owned semantic evidence for observable - Resume uses stage- or artifact-owned semantic evidence for observable
result-affecting configuration; profile identity and an effective digest are result-affecting configuration; overlay identity and an effective digest are
provenance, never blanket cache keys. provenance, never blanket cache keys.
- Session templating remains narrow and deterministic rather than becoming a - Session templating remains narrow and deterministic rather than becoming a
general configuration language. general configuration language.

View File

@@ -1,5 +1,9 @@
# Documentation Policy # Documentation Policy
**Base Policy Version:** 1.1
**Last Updated**: 2026-09-25
## Purpose ## Purpose
This policy assigns each documentation topic to one canonical owner. Its goal is This policy assigns each documentation topic to one canonical owner. Its goal is
@@ -59,7 +63,9 @@ secret values.
| --- | --- | --- | --- | | --- | --- | --- | --- |
| Product orientation and minimal end-to-end quickstart | `README.md` | What Narratio is, why it is useful, one shortest successful invocation, and links onward. | Complete command reference, configuration reference, operational procedures, implementation detail. | | Product orientation and minimal end-to-end quickstart | `README.md` | What Narratio is, why it is useful, one shortest successful invocation, and links onward. | Complete command reference, configuration reference, operational procedures, implementation detail. |
| Contributor entry point | `docs/development.md` | Task-oriented reading guide, minimal contributor orientation, baseline validation commands, and links to canonical docs. | Package inventory, architecture rules, subsystem behavior, detailed change recipes. | | Contributor entry point | `docs/development.md` | Task-oriented reading guide, minimal contributor orientation, baseline validation commands, and links to canonical docs. | Package inventory, architecture rules, subsystem behavior, detailed change recipes. |
| Maintainer release procedure | `docs/release.md` | Version selection, candidate preparation and validation, guarded tag publication, release completion boundary, failure recovery, and optional asynchronous inspection. | Script implementation mechanics, current application contracts, and historical release summaries. | | Agent policy | `docs/policy/agents.md` | Agent implementation discipline, authority boundaries, and local commit policy. | Application contracts, architecture, testing policy, and contributor procedures. |
| Release policy | `docs/policy/release.md` | Versioning, release integrity, documentation and validation requirements, immutability, publication controls, and explicit exceptions. | Repository-specific commands, installation, historical summaries, and CI implementation detail. |
| Maintainer release procedure | `docs/release.md` | Prerequisites, concrete candidate validation and publication commands, deliverables, failure recovery, and optional consumer-facing inspection. | General release requirements and exceptions, current application contracts, and historical release summaries. |
| Historical release summary | `docs/releases/<tag>.md` | Immutable summary, compatibility, upgrade, and changes for one released version. | Current maintainer procedure and current application contract details. | | Historical release summary | `docs/releases/<tag>.md` | Immutable summary, compatibility, upgrade, and changes for one released version. | Current maintainer procedure and current application contract details. |
| Current application architecture | `docs/policy/architecture.md` | System shape, normative ownership, dependency direction, architectural boundaries, invariants, safety properties, and non-goals. | Concrete package inventory, implementation mechanics, contributor procedures, decision history, future work. | | Current application architecture | `docs/policy/architecture.md` | System shape, normative ownership, dependency direction, architectural boundaries, invariants, safety properties, and non-goals. | Concrete package inventory, implementation mechanics, contributor procedures, decision history, future work. |
| Documentation organization | `docs/policy/documentation.md` | Documentation ownership, audience boundaries, maintenance rules, and ADR/document lifecycle. | Application architecture or product behavior. | | Documentation organization | `docs/policy/documentation.md` | Documentation ownership, audience boundaries, maintenance rules, and ADR/document lifecycle. | Application architecture or product behavior. |
@@ -100,6 +106,14 @@ configuration, operational, or integration contract. When a workflow crosses
these topics, choose the document that owns the task and link to the other these topics, choose the document that owns the task and link to the other
contracts. contracts.
### Releases
[Release policy](release.md) owns requirements and explicit exceptions;
[the release procedure](../release.md) owns the commands used to satisfy them.
Release notes record history at an immutable tag. Neither the procedure nor a
release note may silently weaken policy or substitute for updates to current
canonical documentation.
### Contracts And Implementation ### Contracts And Implementation
Integration and API documents define externally observable shapes and Integration and API documents define externally observable shapes and

221
docs/policy/release.md Normal file
View File

@@ -0,0 +1,221 @@
# Release Policy
**Base Policy Version:** 1.0
**Last Updated**: 2026-09-25
## Purpose
This policy defines the minimum requirements for selecting, validating,
publishing, verifying, and correcting releases. Its goal is to make every
release intentional, reproducible from an exact source revision, documented
for consumers, and safe from retrospective replacement.
The repository-specific commands that implement these requirements belong in
`docs/release.md`. Historical release summaries belong in `docs/releases/`.
Neither document may weaken this policy, including its explicit repository
exceptions.
## Release Model
A release consists of:
- one exact source commit reachable from the repository's primary branch;
- one immutable version tag identifying that commit;
- one version-matched, checked-in release note; and
- every artifact, image, package, registry entry, or other deliverable the
repository declares for that release.
The repository's primary branch is `main` unless an adopted policy documents
an exception. A release candidate must be committed and pushed to that branch
before its release tag is published.
The source tag is the authoritative release identity. Published deliverables
must be traceable to the tagged source and must agree with its version. A
repository may publish source only. When it publishes additional deliverables,
its release procedure must enumerate them and define how each is built,
identified, published, and verified.
Release automation may validate or publish a release only when its exact
responsibility is documented. Automation must not silently change the source
candidate, move a published tag, replace a published deliverable, or repair a
release in place.
## Versioning And Compatibility
Stable releases use Semantic Versioning in the form `vMAJOR.MINOR.PATCH`, with
no leading zeroes. Each version must be unused locally and in every configured
remote or publication channel before publication begins.
Unless an adopted policy explicitly supports and defines prereleases,
prerelease versions are not permitted.
For releases at or after `v1.0.0`:
- a major release may make intentional incompatible changes;
- a minor release may add backward-compatible behavior; and
- a patch release may make backward-compatible fixes.
Before `v1.0.0`, a minor release may change a documented public, operational,
configuration, data, integration, or compatibility contract when the release
note explains the impact and required consumer action. A patch release must
not intentionally break those contracts within its minor line.
A repository with additional compatibility promises must define them in its
adopted policy or canonical contract documentation. A release note may explain
a compatibility change, but it must not redefine the current compatibility
contract.
## Release Documentation
Every release made under this policy must include
`docs/releases/<version>.md` in the tagged source tree. The filename must use
the complete version tag, and the document must begin with a title containing
the product name and that exact version.
Every new release note must contain these sections:
```markdown
# <Product> vMAJOR.MINOR.PATCH
This release ...
## Summary
## Compatibility
## Upgrade
## Changes
```
Use an explicit statement such as "No action required" when a section has no
substantive content.
Release notes are immutable historical summaries. They should link to current
canonical documentation for exact behavior. Every affected canonical document
must be updated in the same candidate; a release note must not substitute for
current documentation or defer required documentation changes.
## Candidate Preparation And Validation
Each repository must provide one documented release-check command or script
that exercises the complete set of automated source-candidate gates. The
repository-specific procedure must state all additional manual gates.
The required gates are:
- dependency or module hygiene appropriate to the language and ecosystem;
- the complete deterministic, offline default test suite;
- static analysis and linting used by the repository;
- formatting and whitespace checks;
- validation of maintained examples, configuration, schemas, generated
sources, and documentation commands where applicable;
- review of changed local documentation links;
- removal of obsolete roadmap documents under `docs/roadmap/` that describe
completed work included in the release; and
- review for unintended files, generated output, credentials, private data,
and unrelated changes.
## Publication Guards
Immediately before publication, the maintainer or release automation must
fetch the current primary branch and tags from the authoritative remote and
verify all of the following:
- the version has the required format and is not already published;
- the current branch is the primary release branch;
- the worktree and index are clean;
- the current commit is the recorded, validated candidate;
- the authoritative remote branch points to that same commit;
- the matching release note exists in that commit and has the required title
and sections;
- all required approvals and automated gates succeeded for that commit; and
- no local or remote tag already uses the selected version.
Create the version tag against the guarded commit and verify its target before
publishing it. Publish only the exact intended ref and deliverables. Broad
operations such as `git push --tags` are discouraged because they can publish
unreviewed refs unrelated to the release.
The repository-specific procedure must make these guards executable or give
copyable commands for performing them.
## Immutability And Correction
Published version tags and published deliverables are immutable. Do not move,
overwrite, recreate, or delete a published tag. Do not replace an artifact,
image, package, checksum, signature, provenance statement, or release note
under an already published version.
If validation fails before publication, correct the candidate, rerun the
complete gates, and repeat the publication guards. An unpublished local tag
may be removed after confirming that it was never published or used by a
release channel.
If publication or post-publication verification reveals a defect, leave the
published release intact. Correct the defect on the primary branch, choose a
new patch version or other semantically appropriate new version, write a new
matching release note, and perform the complete release procedure again.
A distribution channel's supported yank, deprecation, or advisory mechanism
may warn consumers away from a defective release, but it must not replace that
release's contents or reuse its version.
## Repository Release Procedure
Every adopting repository must maintain `docs/release.md` as the canonical
maintainer runbook for implementing this policy. It must define, in execution
order:
1. maintainer prerequisites and required access;
2. version selection and compatibility review;
3. release-note creation;
4. candidate preparation and the complete validation command;
5. candidate commit, push, and exact commit recording;
6. publication guards;
7. exact tag and deliverable publication commands;
8. authoritative remote and consumer-facing verification; and
9. failure handling and correction.
The procedure should use copyable, fail-fast commands where practical. It must
name the primary branch, authoritative remote, tag form, published
deliverables, supported build targets, release automation responsibilities,
and consumer verification path. It must link to this policy instead of
restating or redefining its requirements.
## Policy Exceptions
### Tag-push completion and asynchronous deliverables
Narratio's automated release responsibility ends when the exact intended tag is
successfully pushed to `origin`. It must not wait for, poll, or check CI/Gitea
results, download assets, or verify their checksums as a completion condition.
Binary and checksum publication is asynchronous; consumer-facing inspection is
optional follow-up, not a gate on the source release.
This deliberately qualifies the base policy's complete-deliverable and
post-publication verification requirements. CI reliability is outside the
release command's scope; an unavailable publication service must not cause an
automated releaser to wait indefinitely or claim to repair a published version.
Compensating controls are complete local candidate validation (including supported
cross-builds and a host version check), exact source/tag guards, immutable source
tags, asynchronous build validation, and non-overwriting asset publication.
Successful tag publication is not evidence that binary assets are available.
Optional inspection and corrective-release procedures belong in
[the release procedure](../release.md).
### Authoritative publication scope
Narratio's synchronous publication guards inspect the authoritative `origin`
remote and its `main` branch, not every configured Git remote or a Gitea release
entry. The command does not add release-service or registry availability checks.
This qualifies the base policy's all-channel unused-version requirement.
Other remotes are not Narratio release authorities, and Gitea asset publication
is asynchronous. The compensating controls are local and origin tag uniqueness,
exact candidate matching, and the publisher's non-overwrite settings. Any known
already-published version or conflicting deliverable remains ineligible for
reuse: choose a new version rather than bypassing guards. A future additional
distribution channel requires deliberate policy/procedure updates.

View File

@@ -1,5 +1,9 @@
# Testing Policy # Testing Policy
**Base Policy Version:** 1.0
**Last Updated**: 2026-09-25
## Purpose ## Purpose
Our tests exist to make **incorrect changes expensive and correct changes cheap**. Our tests exist to make **incorrect changes expensive and correct changes cheap**.

View File

@@ -1,71 +1,97 @@
# Releasing Narratio # Releasing Narratio
This document is the maintainer procedure for creating a Narratio source and This is the maintainer runbook for the [Release Policy](policy/release.md).
binary release. The synchronous release boundary is a successful push of one Its [explicit exceptions](policy/release.md#policy-exceptions) preserve the
new tag to `origin`; Woodpecker and Gitea publication happen later and do not successful tag push as the automated responsibility boundary. Binary publication
change that result. is asynchronous; later consumer-facing inspection is optional.
## Prerequisites and publication scope
Use a checkout on `main` with Git authentication permitting fetches and pushes
to `origin`, the authoritative Git remote. Install Git, a POSIX shell, standard
Unix build tools, and the Go toolchain below. Make required modules available
before offline validation. No model/provider credentials are needed. Gitea
publication credentials belong to CI's secret store, not the local command.
Synchronous guards inspect local tags and `origin`, not every configured remote
or Gitea release entry. Do not select a version known to have been published in
any channel, even if these guards cannot see it.
## Go prerequisite ## Go prerequisite
Release preparation requires the maintained Go 1.26 baseline. Tag CI currently Release preparation requires the maintained Go 1.26 baseline. Tag CI currently
uses the explicitly pinned `golang:1.26.7` image for candidate validation and uses the explicitly pinned `golang:1.26.7` image for validation and asset builds.
asset construction; that asynchronous work does not change the tag-push That asynchronous work does not change the tag-push completion boundary.
completion boundary.
## Choose a version and write its note ## Choose a version and write its note
Narratio is past `v1.0.0`. Use an unused stable tag in the exact form Select an unused stable version under the
`vMAJOR.MINOR.PATCH`: [versioning rules](policy/release.md#versioning-and-compatibility). Narratio is
past v1.0.0; intentional CLI/configuration breaks require a major release.
- increment `MINOR` for backward-compatible features; Create `docs/releases/vMAJOR.MINOR.PATCH.md` using the
- increment `PATCH` for backward-compatible fixes; and [required note structure](policy/release.md#release-documentation).
- reserve a new `MAJOR` for an intentional breaking documented contract. Describe CLI, configuration, artifact, integration, and operating-contract
changes, and the required operator action. Link to current canonical
documentation for exact behavior.
Before preparing the candidate, create ## Prepare and record the candidate
`docs/releases/vMAJOR.MINOR.PATCH.md` with this structure:
```markdown Before committing, perform these manual reviews in addition to automated checks:
# Narratio vMAJOR.MINOR.PATCH
This release ... - Confirm compatibility/version selection and update affected canonical
documentation and maintained examples.
- Remove completed roadmap documents covering work included in this release;
retain pending work. Their history remains in Git. Do not delete historical
release notes.
- Review the diff, staged changes, and untracked files for credentials, private
data, generated output, unintended files, and unrelated changes.
- Review changed documentation links and behavior-bearing commands. Automated
link checks supplement rather than replace review.
## Summary Commit the note and candidate changes, then push that commit to `main` through
the ordinary development workflow. Record the exact candidate:
## Compatibility ```sh
git rev-parse HEAD
## Upgrade
## Changes
``` ```
The compatibility section identifies relevant CLI, configuration, artifact, Do not create a tag until `origin/main` points to that same commit. If the
integration, or operating-contract changes. The upgrade section states the candidate changes, repeat the reviews and validation.
required operator action, or explicitly says that no special action is
required. Release notes are immutable historical summaries; link to the
current canonical documentation for detailed behavior.
Commit the note and all candidate changes, then use the ordinary development
workflow to push that commit to `main`. Do not create a release tag before the
candidate is committed and `origin/main` contains the exact same commit.
## Validate the candidate ## Validate the candidate
Run the shared checker from any directory: From the repository root, run:
```sh ```sh
scripts/check-release-candidate.sh vMAJOR.MINOR.PATCH scripts/check-release-candidate.sh vMAJOR.MINOR.PATCH
``` ```
The script also works when invoked by its absolute path from another directory.
It validates the version and matching note, module hygiene, formatting, It validates the version and matching note, module hygiene, formatting,
whitespace, uncached tests, race tests, static checks, documentation, examples, whitespace, uncached tests, race tests, static checks, documentation, examples,
and three official cross-build assets. It uses `GOWORK=off`, does not contact and three cross-build assets. It uses `GOWORK=off`, does not contact application
application services, CI, or Gitea, and does not create tags or modify tracked services, CI, or Gitea, and does not create tags or modify tracked source.
source. Fix any failure on `main`, commit it, push it normally, and rerun the Fix failures on `main`, commit, push normally, and rerun validation.
checker.
The checker builds Linux assets for `amd64` and `arm64` and a macOS asset for The macOS cross-build proves compilation, not native runtime behavior.
`arm64`. The macOS cross-build proves compilation; it is not native macOS
runtime evidence. ## Declared deliverables and automation
The source release is the exact version tag at the validated commit.
The tag-triggered `.woodpecker/release.yml` validates the tagged source,
runs `scripts/build-release-assets.sh`, and publishes these Gitea assets:
- `narratio-vMAJOR.MINOR.PATCH-linux-amd64`
- `narratio-vMAJOR.MINOR.PATCH-linux-arm64`
- `narratio-vMAJOR.MINOR.PATCH-darwin-arm64` (best effort)
- `SHA256SUMS`
The builder embeds the version, disables ambient Go workspaces, and checks a
host binary's `version` output. The release publisher uses the matching
checked-in note and generates SHA-256 checksums. Existing files are skipped and
overwrite is disabled. No image or package-registry deliverable is declared.
CI does not choose versions, modify source candidates, or move tags.
## Publish the tag ## Publish the tag
@@ -78,27 +104,64 @@ scripts/release.sh vMAJOR.MINOR.PATCH
The command fetches and checks `origin/main`, re-runs candidate validation, The command fetches and checks `origin/main`, re-runs candidate validation,
then fetches and checks again before creating an explicitly unsigned lightweight then fetches and checks again before creating an explicitly unsigned lightweight
tag for the originally recorded commit. It refuses dirty, divergent, changed, tag for the originally recorded commit. It refuses dirty, divergent, changed,
or already-tagged candidates. It pushes only: or already-tagged candidates. It verifies the local tag target and pushes only:
```text ```text
refs/tags/vMAJOR.MINOR.PATCH:refs/tags/vMAJOR.MINOR.PATCH refs/tags/vMAJOR.MINOR.PATCH:refs/tags/vMAJOR.MINOR.PATCH
``` ```
It never commits changes, pushes `main`, force-pushes, moves a tag, or pushes It never commits changes, pushes `main`, force-pushes, moves tags, or pushes all
all tags. A successful push of that exact ref completes the release command; tags. Successful publication of that ref completes the command; it prints the
the command prints the tag and commit, then returns without waiting for CI, tag and commit and returns without waiting for CI, querying Gitea, downloading
querying Gitea, downloading assets, or checking checksums. assets, or checking checksums.
If a failure occurs before the tag is created, correct the candidate on `main` ## Failure handling
and repeat validation. If the push fails after local tag creation, the local tag
is intentionally retained for inspection and the command must not be retried Before tag creation, correct the candidate on `main` and repeat validation.
blindly. Once the upstream tag has been pushed, it is immutable. Correct any If a push fails after local tag creation, the local tag is retained for inspection.
defect or failed asynchronous publication with a new patch version, a new Do not retry blindly or assume the remote received nothing: a connection failure
release note, and the complete procedure again. can leave publication uncertain. Inspect the exact remote ref before taking any
local-tag cleanup action. This is recovery from a failed command, not a
post-success publication gate.
After publication, follow the
[immutability and correction rules](policy/release.md#immutability-and-correction).
Correct defects or failed asynchronous publication with a new semantically
appropriate version, matching note, and the complete procedure. Never replace
existing tagged assets in place.
## Optional asynchronous inspection ## Optional asynchronous inspection
After a successful tag push, a human may later inspect the tag-triggered A human may later inspect the tag-triggered Woodpecker job and Gitea release.
Woodpecker run and the corresponding Gitea release for binaries and checksums. This is optional follow-up, never part of the automated releaser's completion
This is optional follow-up only. Automated releasers must not wait for, poll, criteria. Do not wait for or poll CI/Gitea from the release command.
or treat CI/Gitea completion as a condition of the successful tag push.
For optional source verification, substitute the released version below and
compare the remote target to the recorded candidate hash:
```sh
git ls-remote --tags origin refs/tags/vMAJOR.MINOR.PATCH
git rev-parse 'refs/tags/vMAJOR.MINOR.PATCH^{commit}'
```
Download the three named binaries and `SHA256SUMS` from the matching Gitea release
into an empty inspection directory. In that directory, verify on Linux:
```sh
sha256sum --check SHA256SUMS
```
On macOS, use `shasum -a 256 --check SHA256SUMS`. After successful verification,
make the matching host binary executable and run its version command, for example
on Linux amd64 (replace the version in both commands):
```sh
chmod +x ./narratio-vMAJOR.MINOR.PATCH-linux-amd64
./narratio-vMAJOR.MINOR.PATCH-linux-amd64 version
```
Expected output is `narratio vMAJOR.MINOR.PATCH`. Use only the matching architecture
on other supported hosts. Checksums establish consistency with the downloaded
checksum file, not a new signature or independent authenticity guarantee.
Missing assets are an asynchronous publication problem, not grounds to move or
reuse the successfully published source tag.

35
docs/releases/v2.2.1.md Normal file
View File

@@ -0,0 +1,35 @@
# Narratio v2.2.1
This maintenance release consolidates checkpoint persistence for transcription
and analysis without changing their operator-facing behavior.
## Summary
Transcribe and analyze now share one internal operation for preparing isolated
checkpoint candidates, saving them, and promoting successfully saved progress
into live state. Each stage retains its own progress model and recovery policy.
## Compatibility
CLI commands, configuration, manifest schemas, artifact formats, and external
integration contracts are unchanged. Speaker concurrency, artifact selection,
force behavior, and ordinary resume semantics are preserved. No dependency
upgrade or new external-tool version requirement is introduced.
## Upgrade
No special upgrade action or configuration migration is required when upgrading
from v2.2.0. See the [v2.2.0 release notes](v2.2.0.md) when upgrading from an
earlier version for the original speaker-checkpoint upgrade considerations.
## Changes
- Replace duplicate analyze/transcribe save-and-promote sequences with a
shared, private checkpoint helper.
- Isolate checkpoint collections from live state, including analyze records
normalized during a transcription checkpoint save.
- Preserve transcription's caller-owned locking and failure handling, and
analysis's working/committed collections and rollback behavior.
- Add focused checkpoint integrity tests while retaining stage and application
recovery coverage.
- Document the shared [checkpoint persistence boundary](../internal/manifest.md#checkpoint-persistence-boundary).

288
docs/roadmap/audita.md Normal file
View File

@@ -0,0 +1,288 @@
# Adopt Audita v2 and ConfigKit v0.4.0
Status: implemented (2026-09-25); release pending.
## Goal
Migrate Narratio's `polish` integration from Audita's former command/configuration
contract to Audita v2.0.0. Keep Narratio responsible for orchestration and Audita
responsible for correction behavior and LLM execution configuration.
Adopt a consistent provider-named credential list for both Audita and Notarius,
so operators define each secret once and explicitly share it with the downstream
applications that need it. This is a clean cutover without backward-compatibility
shims.
Adopt ConfigKit v0.4.0 and use “overlay” consistently for Narratio's selected
pipeline configuration, distinct from downstream LLM model profiles.
Production runs use Audita's default reporting configuration: Narratio passes
neither `--debug` nor `--reporting=false`. Normal reports remain available without
enabling debug diagnostics. Adding debug reporting through Narratio's testing
profile is deferred.
This document defines the intended end state, migration scope, and policy.
The [implementation plan](implementation.md) owns implementation sequencing and
verification steps.
## Baseline and upstream contract
The baseline is Narratio v2.2.1 and the Audita checkout tagged v2.0.0. Upstream
references are Audita's `docs/migrations/v2.md`, `docs/cli.md`,
`docs/integrations/subprocess.md`, and `docs/integrations/output-files.md`,
available in the sibling `../audita/` checkout. Narratio's current contract is
documented in [Integration: Audita](../integrations/audita.md).
The current integration is not compatible with Audita v2:
- It requests `--report-json` by default; that flag has been removed.
- It can pass retired endpoint, model, concurrency, and work-directory-retention
flags.
- It expects one JSON report instead of the normal v2 report bundle.
- Its single forwarded `AUDITA_LLM_API_KEY` has no implicit meaning in v2;
an Audita backend must explicitly reference that environment variable.
- Its semantic fingerprint sorts modules, although Audita treats module order
and repetitions as meaningful.
Audita v2 requires a version-2 configuration file. An explicit `--config` selects
one; otherwise Audita performs its own documented discovery. Backend definitions
own endpoints, credentials, and capacity. PromptKit profiles own models and
per-attempt controls. Audita owns retry/repair policy and operation deadlines.
Narratio's generated invocation YAML is a diagnostic record, not a substitute
for that Audita configuration file.
## Target architecture
Retain the existing subprocess boundary and `polish` stage. Do not introduce a
second correction engine, an in-process Audita dependency, or a generic external
tool configuration framework.
Narratio owns:
- Selection of the executable and the overall invocation timeout/cancellation.
- Transcript and glossary inputs, run-local output placement, validation of the
corrected transcript, and promotion to the existing polished transcript
identity.
- Explicit configuration/profile selections and supported domain overrides.
- Deliberate credential forwarding, secret-safe invocation diagnostics, and
manifest references to results and reports.
- Existing stage completion, resume, force, publish, restore, and cleanup
behavior.
Audita owns its configuration schema and discovery, backend/model configuration,
provider execution, correction sequence, recovery behavior, and report contents.
Narratio does not translate old settings into a generated v2 configuration or
duplicate Audita's complete validation logic.
## Configuration and invocation migration
### ConfigKit and pipeline overlays
Upgrade Narratio's ConfigKit dependency from v0.3.1 to v0.4.0. ConfigKit's
selected-configuration terminology changes from profile to overlay: the Go API
uses `Options.Overlay`, `LayerOverlay`, and `CodeOverlay*`; source layers and
diagnostic codes use `overlay` and `overlay.*`. Composition, precedence, secret
resolution, and lifecycle semantics otherwise remain unchanged.
Narratio's pipeline-selection interface becomes `--overlay`, selecting
`overlays/<name>.yml` beside the root pipeline file. Remove `--profile` and old
selected-directory discovery without aliases or fallbacks. Preserve existing
base selection for omission, explicit empty selection, and `default`.
Configuration inspection, diff descriptions, internal selection names, and
newly written selection provenance use overlay terminology as well.
Maintain existing value-based digest and stage-reuse semantics; renaming
informational selection provenance is not a reason to invalidate completed
work or automatically rewrite historical manifests. Strict manifest decoding
rejects retired provenance fields; operators must deliberately migrate that
informational member on a backed-up manifest, preserving execution/checkpoint
state. Update maintained examples and operator migration guidance for the
directory, flag, and provenance changes.
This rename does not apply to downstream model profiles, Scriptorium
`profile_id`, Audita's proposal/validation profiles, or Notarius's
`config_profile`. Nor does it prohibit ordinary explicit imports from a directory
named `profiles`. Narratio overlays do not automatically select downstream
overlays or profiles. These are independently owned choices.
### Audita v2 configuration
Keep binary, timeout, explicit config-path selection, and surviving explicit
domain overrides such as transcript description, output schema, and modules.
Allow Audita's native configuration discovery when no config path is selected;
do not impose an additional requirement to supply an explicit path.
Provide optional Audita overlay, proposal-profile, and validation-profile
selectors, passed through to their corresponding CLI flags. Omission leaves
Audita's own defaults and validation-profile inheritance in control. These are
Audita selectors, not automatic translations of Narratio overlay names.
Retire the Narratio settings that mirror removed Audita endpoint/model/capacity
flags and work-directory retention. Move their operational meaning into the
operator-maintained Audita configuration and profiles. Remove stale adapter
fields, validation, invocation metadata, examples, and tests along with them.
Remove the old report toggle and both adapters' singular `llm_api_key` fields
from accepted Narratio configuration. Do not retain deprecated aliases,
automatic conversion, ignored fields, or a v1 execution path. Existing strict
configuration decoding rejects removed fields. Provide migration guidance and a
release compatibility notice rather than runtime compatibility machinery.
Preserve the distinction between omitted modules and an explicitly empty module
list: omission requests Audita's configured/default sequence; an empty list
requests no correction modules. Preserve order and repetitions rather than
sorting or deduplicating. Do not broaden this into a change to unrelated
adapters' module semantics.
Normal invocations no longer pass `--report-json`, `--work-dir-retention`, or
debug-work-directory flags as a way to obtain reports. They need no reporting
override: Audita writes its ordinary report bundle by default. The old
Narratio `report` toggle must not silently become `--reporting=false`.
The production Audita configuration must also retain reporting enabled and debug
disabled. Omitting CLI flags does not override an operator's explicit external
configuration. Document this distinction rather than silently adding forced
boolean overrides or rejecting otherwise valid Audita configuration.
## Credentials
Define secrets once under provider-oriented environment-variable names, such as
`OPENROUTER_API_KEY` and `RAKESTRAWHOME_API_KEY`, through the process environment
or Narratio's existing secrets-directory bootstrap. These names are examples,
not a fixed provider registry; application-specific names are not required.
Add `pipeline.audita.credentials` and `pipeline.notarius.credentials` as lists
of Narratio typed secret references. Each entry names the environment variable
whose captured value is forwarded under that exact name. Omission or an empty
list forwards no credentials. The same reference may appear in both adapters'
lists without duplicating its stored secret value. An illustrative configuration
fragment is:
```yaml
pipeline:
audita:
credentials:
- OPENROUTER_API_KEY
- RAKESTRAWHOME_API_KEY
notarius:
credentials:
- OPENROUTER_API_KEY
```
Resolve references through the existing configuration/secret-loading mechanism
before adapter execution, preserving its nonempty-value requirement. Forward
the captured values rather than rereading the parent environment during a run.
Retain the minimal child execution environment plus each adapter's explicit
credential list; do not forward every secret found during bootstrap.
Audita backends select these names through `credential`; the current Notarius
PromptKit profiles select them through `api_key_env`. Narratio neither inspects
downstream configuration to infer required credentials nor translates names,
registers providers, or duplicates backend configuration. Audita resolves
credentials for every surviving configured backend, even one not selected by
a profile, so its list must cover all those references.
Generalize Notarius's current single-name forwarding and replace Audita's fixed
`AUDITA_LLM_API_KEY` destination with this shared convention. Use existing shared
secret and subprocess facilities, extending narrow helpers where needed rather
than introducing a new secret-management framework. Register every forwarded
credential with captured-output redaction, including custom names and multiple
keys. Values must not enter arguments, generated configuration, manifests,
logs, or examples. As today, downstream tools remain responsible for files they
write directly; this does not add arbitrary downstream-file scanning.
## Ordinary reports and result handling
Replace the old `audita.report.json` handling with Audita's normal `errors.yml`,
`recoveries.yml`, and `report.md` bundle. With a file output, Audita writes these
beside the corrected transcript; an arbitrary report destination is not supplied
through the removed report flag.
Discover the reports at their defined run-local locations and retain them as
diagnostics using Narratio's existing manifest and diagnostic lifecycle. Keep
them distinguishable from the canonical polished transcript. Adapt report
references, publication/restore coverage, and operator inspection guidance so
the bundle is not lost or confused with an older run's JSON report. Do not
fabricate a legacy JSON report or delete historical diagnostics as part of the
migration.
Retain existing bounded, confined file handling. Replace JSON-specific report
handling with only the validation needed for consuming the v2 bundle; do not
introduce a second comprehensive report-schema validator or make incidental
Markdown wording a contract. Report locations must be discoverable without
parsing human-readable stderr. Detailed report-counter ingestion is not required
for this migration.
Audita's exit status remains authoritative. Exit zero with a valid corrected
transcript may include recoverable LLM failures, including a normalized result
with no model corrections. Preserve the reports so operators can assess that
outcome; do not add an unrequested fail-on-recovery or minimum-correction policy.
Conversely, a nonzero exit must fail polish even if a transcript file exists:
Audita can fail while writing required reports after writing the transcript.
Preserve available failure diagnostics without requiring early failures to have
produced a complete report bundle. Failed output must not become the canonical
successful result.
## Resume and semantic evidence
Update polish's semantic evidence for the new result-affecting selections and
remove retired endpoint/model fields. Include explicit config/overlay/profile
selection and preserve ordered module semantics, including omitted versus empty
selection. Version the changed evidence so incompatible older evidence is not
mistaken for a valid match when polish is considered for reuse.
Keep the existing boundary for opaque downstream configuration: Narratio does
not recursively hash Audita configuration, overlays, and profile contents.
Operators force polish when changing contents behind unchanged selectors.
Timeouts, credential values, reporting details, and other execution-only settings
must not become blanket semantic invalidation keys. Do not rerun unrelated or
unselected stages merely because the integration was upgraded.
## Migration guidance and verification
Update the canonical [configuration reference](../config.md),
[Audita integration contract](../integrations/audita.md),
[Notarius integration contract](../integrations/notarius.md),
[polish internals](../internal/stage-polish.md), maintained examples, and relevant
operations/troubleshooting guidance when implementation lands. Cover:
- Moving selected Narratio pipeline files to `overlays/`, replacing `--profile`
with `--overlay`, and distinguishing configuration overlays from model profiles.
- Updating ConfigKit API/source attribution and verifying unchanged effective
values retain existing semantic reuse behavior.
- Preparing and validating an Audita v2 configuration and its profiles before
switching the executable; copying an old v1 configuration is insufficient.
- Moving endpoint, model, capacity, and credential selections to their v2 owners.
- Replacing both singular `llm_api_key` settings with explicit `credentials`
lists, storing each provider key once, and matching downstream credential
references to those names. State clearly that old fields are removed.
- Using normal reports to inspect recoveries and failures without debug mode.
- Force/resume expectations and the treatment of existing completed sessions.
- The explicitly deferred nature of Narratio testing-profile debug support.
Verification should exercise the real adapter boundary with offline subprocess
fixtures and focused stage/configuration tests: accepted v2 arguments, omitted
defaults, ordered/empty modules, secret-safe forwarding, successful report
capture, recoverable-error success, nonzero exit with an existing transcript,
failure diagnostics, and semantic reuse/invalidation. Update existing behavioral
tests rather than retaining assertions for removed flags or exact stderr prose.
Where practical, verify invocation against the tagged Audita CLI without live
provider calls. Follow the repository's testing and documentation policies.
Credential tests must cover both adapters, multiple custom names, reuse of one
secret by both tools, no forwarding of unselected secrets, captured-value
semantics, and redaction of every forwarded value. Verify removal of obsolete
configuration fields without preserving their compatibility behavior.
## Scope boundaries
No changes to pipeline order, transcript identity, downstream artifact
definitions, or provider algorithms are intended. No automatic v1 configuration
converter, Audita-internal resume mechanism, runtime binary-version negotiation,
or live-service release gate is required. Debug-profile integration and ingestion
of Audita's debug-only execution artifacts are future work.
The Notarius change is limited to credential configuration, forwarding, and
associated diagnostics/documentation/tests; extraction and cache behavior are
unchanged. This migration breaks existing pipeline configurations using removed
fields; account for that explicitly in Narratio release versioning.

View File

@@ -1,416 +1,465 @@
# Implementation Plan: Speaker Checkpoints and Replayable Uploads # Implementation Plan: Audita v2 and Shared Provider Credentials
Status: Implementation complete; Stages 1-7 complete. Status: Complete (2026-09-25).
## Scope and Instructions ## Scope and working instructions
Implement [the feature roadmap](transcribe-checkpoints-and-replay.md). This plan Implement [the Audita roadmap](audita.md). The baseline is Narratio commit
replaces the completed Notarius-profile plan; that work remains in Git history. `70f1dbf` (v2.2.1), with ConfigKit v0.4.0 and Audita v2.0.0 as the target
Complete the numbered stages in order, one bounded implementation prompt per upstream contracts. This replaces the completed checkpoint-refactoring plan,
stage for gpt-5.6-terra. Record completion and actual verification results here. which remains in Git history.
Intermediate stages are not a finished feature and must not be released alone.
Complete Stage 1 through Stage 8 in order, one bounded implementation prompt per
Before working, read `AGENTS.md`, `docs/development.md`, all three policies in stage for gpt-5.6-terra. Record completion and actual verification results under
`docs/policy/`, the roadmap, and the stage-specific preparation below. Use the each stage. These instructions apply to the implementation sprint; the planning
maintained Go 1.26 toolchain. Preserve operator choices, speaker filenames, pass changes documentation only. Intermediate stages are not release candidates.
bounded concurrency, streaming, and existing credentials/settings. Do not add Do not add compatibility code to make intermediate states look like a supported
new commands, dependencies, service requirements, arbitrary speaker limits, release.
strict transcript schemas, or a generic checkpoint framework. No release or
upstream service work is part of this plan. Before each stage, read `AGENTS.md`, `docs/development.md`, and all policies
under `docs/policy/`: agents, architecture, documentation, testing, and release.
## Settled Design Decisions Read this plan's selected design and that stage's preparation. Use Go 1.26 and graph-first code
discovery; inspect current files when graph results are incomplete. Preserve
### Progress Representation and Recovery unrelated changes. Test at behavioral owners rather than replicating every case
across configuration, adapter, stage, and command tests.
Add optional `transcribe_state_version` (version 1) and `transcribe_speakers`
to `manifest.StageRecord`. The latter is a map keyed by the existing derived The user approved a clean cutover: no Audita v1 runner, deprecated aliases,
speaker ID, containing completed results only. Absence means that work must be compatibility shims, generated configuration conversion, or silently ignored
done; a separate pending/running/failed state machine is unnecessary. Aggregate old settings. Do not broaden that decision into a purge of unrelated legacy
stage status/error remains authoritative for invocation failure. A versioned code or historical session data.
empty collection is meaningful: no earlier completions are reusable.
## Selected design
Use a typed `TranscribeSpeakerRecord` with fingerprint version/digest,
session-relative audio path, audio SHA-256 and size, one `ArtifactRecord` output ### ConfigKit and Narratio overlay terminology
of kind `transcript_raw`, output size, and producer run ID. The output carries
its session-relative canonical path and SHA-256. No new transcript source IDs, Upgrade ConfigKit from v0.3.1 to v0.4.0 before adapter work. Rename its
synthetic schema contracts, timestamps, or historical attempt collections are `Options.Profile`, `LayerProfile`, and any `CodeProfile*` uses to their overlay
needed. Existing aggregate diagnostics can retain attempt/status/duration data equivalents. Selected pipeline files move from `profiles/<name>.yml` to
for work performed in the current invocation; do not fabricate that information `overlays/<name>.yml`; no fallback directory or alias is permitted.
for reused outputs.
Rename Narratio's pipeline-selection flag to `--overlay` everywhere it is
Keep the session-manifest schema identifier unchanged for this optional additive accepted, including convenience commands and configuration inspection. Rename
state; validate supported per-stage versions and retain strict decoding. New application-owned selection types/helpers, help, errors, and current inspection
Narratio reads old manifests. Old binaries may reject the added fields under labels consistently. `config diff` still takes two positional selections,
their existing strict decoding; document this downgrade limitation. now described as overlays. Preserve omission, explicit empty, and `default`
as base selection; do not add a persistent default selector or new precedence.
For pre-feature manifests with no speaker evidence, regenerate transcription
once when transcribe is next selected, even if the aggregate status succeeded. Rename newly written informational provenance to overlay terminology, including
Old records do not bind individual transcript results to the audio bytes they `selected_overlay` in manifest configuration provenance. Do not add a dual-field
used. Do not guess that association from current files, old `per_file` metadata, reader, automatically rewrite historical manifests, or introduce a manifest-version
or abandoned run directories. This is the conservative upgrade path, not a new rejection solely for this informational rename. Existing strict typed decoding
general migration system. No other stage or unselected range is forcibly run. rejects retired provenance fields. Document backed-up operator migration of
that informational member without changing execution/checkpoint state; it does
### Reuse and Persistence not become resume authority. Preserve
semantic fingerprints and effective-value digest rules when values are unchanged.
Compute a versioned per-speaker fingerprint from speaker ID, session-relative
audio identity, actual audio SHA-256/size, and the existing transcribe semantic Only Narratio pipeline configuration selection is renamed. Keep model/profile
configuration fingerprint (URL and language). Do not include invocation ID, fields such as Scriptorium `profile_id`, Audita `proposal_profile` and
absolute workspace root, concurrency, retry settings, timeout, or credentials. `validation_profile`, and Notarius `config_profile` unchanged. Explicit imports
Stream input hashing with cancellation; do not trust stored input checksums from directories named `profiles` remain legal; only selected pipeline overlay
alone. Recheck input bytes before accepting a new result to catch changes discovery changes. Do not globally replace the word “profile.”
observed during transcription; fail that job without checkpointing mismatched
evidence. This is not a hostile-filesystem snapshot or concurrent-editor ### Configuration and credentials
transaction guarantee and requires no extra audio copies or file locks.
- Both `pipeline.audita.credentials` and `pipeline.notarius.credentials` are
Validate reusable output identity, canonical location, JSON, checksum, and size. lists of ConfigKit secret references. Use `[]configkit.Secret`; each element
Use existing confinement/file primitives. Missing or corrupt regular outputs is an actual reference rather than a nullable pointer. Existing ConfigKit
become work; unsafe paths/non-regular conflicts follow existing safety errors, validation owns name/value resolution. Omitted, null, or empty lists mean no
not recursive deletion. Missing required audio is an input error, not permission additional credential forwarding.
to reuse an unverifiable transcript. Removed inputs are removed from the current - Define each key once through existing environment/secrets-directory bootstrap.
collection and aggregate outputs without deleting arbitrary files. Forward it under its original name to each adapter whose list includes it.
No alias mappings, provider registry, downstream config inspection, extra
One stage-owned mutex serializes candidate collection construction, manifest bootstrap, or inheritance of the entire environment.
save, and installation of committed state. Save a detached candidate and only - Repeated names need no new rejection rule: forwarding the same captured
then update live authority, following analyze's pattern. Workers must not mutate reference once suffices. Arbitrary valid variable names remain supported;
the live manifest outside that serialized section. Keep expensive HTTP work provider names in the roadmap are examples, not an allowlist.
outside the mutex. Stop dispatch/acceptance on checkpoint failure, join workers - Add a narrow shared helper in `internal/adapters/subprocess` converting resolved
before return, and preserve the last successfully committed collection. references to `EnvOverrides` and `SensitiveEnvNames`. It checks the existing
resolved/nonempty requirement for direct adapter callers but never resolves
Before launching requests, durably checkpoint the reconciled collection. For secrets or rereads environment values. Errors expose no values. Both adapters
force, that collection is empty: this prevents later ordinary retries from use it; the ConfigKit upgrade is owned by Stage 1, not this helper. No new
resurrecting pre-force outputs. If this initial save fails, do not start requests credential service is needed.
or overwrite outputs. Force again clears the current collection again; ordinary - Configuration projections and diagnostic metadata contain reference names
retry retains replacements already checkpointed after the previous force. only. Register all forwarded names for existing captured-stream redaction.
Downstream tools remain responsible for files they write themselves.
Save each validated result at its canonical raw-transcript location before - Remove both singular `llm_api_key` fields. For Audita also remove `base_url`,
checkpointing it. Run-local files remain staging/diagnostics, not reuse `model`, `validation_model`, `total_llm_concurrency`,
dependencies. Bytes left by an unsuccessful checkpoint have no completion `proposal_llm_concurrency`, `validation_llm_concurrency`,
authority. A worker may checkpoint a completed result using the parent stage `work_dir_retention`, and `report`, including defaults and projections.
context even if a sibling canceled the work context; parent cancellation or a - Retain Audita `binary`, `timeout`, `config_path`, `transcript_description`,
checkpoint failure may prevent that save. Guarantee retention of committed `output_schema`, and `modules`. Add optional string selectors `overlay`,
work, not all responses that happened to finish during cancellation. `proposal_profile`, and `validation_profile`: empty/unset means no CLI
override. Audita owns downstream file/profile validation and native config
### Multipart Replay Mechanism discovery. Narratio overlay names are not implicitly Audita overlay names.
- Preserve nil versus non-nil empty `modules` through loading, projection,
Replace the pipe/producer upload mechanism with a small pull-based multipart cloning, composition, adapter defaults, and request overrides. Nil omits the
body backed by the audio reader. Use `mime/multipart.Writer` to encode a bounded flag; empty passes `--modules` with an empty argument; nonempty joins in order
metadata prefix and suffix around the file payload: capture the prefix after with repetitions intact. A nil request override uses the configured selection.
`CreateFormFile`, then encode the language field and closing boundary as the Avoid clones that collapse empty slices to nil. YAML null follows unset
suffix. Generate this framing once per application attempt. Each body combines behavior. Other adapters' module semantics do not change.
fresh readers for prefix, freshly opened audio, and suffix using `io.MultiReader`.
No full-audio buffer or temporary multipart spool is needed. ### Invocation, reports, and failure
The initial body and `Request.GetBody` use the same factory/framing. Each owns Use `process INPUT --glossary PATH --output PATH` plus selected surviving
an independent audio handle. Give bodies idempotent Close and context-triggered overrides. Production passes no reporting or debug switches, including
closure (for example `context.AfterFunc`), without holding a mutex across a `--debug`, `--reporting=false`, `--report-dir`, or `--work-dir`.
blocking Read. Read/Close coordination must release a blocked source and retain Remove required `WorkDir` and legacy `ReportPath` request/result plumbing.
genuine source-read/close errors while not treating deliberate early closure as Document production external-config defaults without forcibly overriding or
source failure. The attempt owns cleanup of all created bodies, including rejecting deliberate external reporting/debug choices.
replays; reject new body creation after its context expires.
Replace Audita's long positional config-values constructor with typed runner
Remove the old producer `Wait` dependency. Track body-local source errors with configuration. Keep timeout parsing in composition and subprocess cancellation
synchronization so a swallowed upload read error cannot become a successful through the existing runner. No version probe or automatic config-validation
transcript, and a deliberately closed original body cannot poison a successful subprocess is required.
replay. Keep the outer retry policy and per-attempt context. Do not add replay
counters to the user retry budget or depend on Go's exact internal retry count. The corrected transcript remains the only canonical polish output, with existing
Preserve ordinary HTTP redirect policy; body replay can also enable Go's identity, path, validation, and bounded file handling. Discover exactly
body-preserving redirects. Do not introduce a new redirect restriction. `errors.yml`, `recoveries.yml`, and `report.md` beside the requested output.
Represent available paths in a small typed report bundle in `PolishResult`.
## Stage 1: Add Durable Speaker Completion State Fixed names belong to the adapter; do not parse stderr or recursively scan.
Status: Complete. Reports are diagnostics, not a new correctness gate:
Completion marker (2026-09-21): Added optional versioned transcribe-owned - Bound reads of present reports using the existing named 16 MiB report limit;
per-speaker completion records, strict load/save validation, isolated collection retain confined regular-file handling and errors identifying Audita, the file,
cloning, legacy aggregate-only compatibility, and lifecycle-preservation and limit. No new smaller limits or report schema/status/count validation is
coverage. Verified with `go test ./internal/manifest` and `git diff --check`. necessary when Narratio only preserves bytes; Markdown needs no parser.
- Missing files are not independently fatal: external configuration can disable
Preparation: `internal/manifest/manifest.go`, `store.go`, `analyze_state.go`, reports and early failures may produce none. Default-reporting success tests
their tests, and `docs/internal/manifest.md`. must nevertheless demonstrate capture of all three files.
- On process failure, preserve available diagnostics and the original error;
1. Implement the additive fields, record type, version constants, validation, report-inspection errors must not hide it. Never promote an output merely
and deep-copy helper described above in a focused transcribe state file. because it exists following a nonzero exit.
2. Validate ownership by the transcribe stage, supported versions, required - Exit zero with a valid transcript may include recoverable errors or no model
completed-record evidence, output kind, safe relative paths, SHA-256 values, corrections. Accept it without a fail-on-recovery or minimum-correction rule.
sizes, and producer identity consistency. Use existing speaker IDs as-is;
do not apply analysis-artifact key regexes or copy unrelated analysis limits. Keep reports next to the run-local transcript, not in a second canonical
3. Integrate validation with both load and save. Preserve speaker state through destination. Register present report paths in the existing `StageResult.Logs`
running/failed/stale transitions and aggregate result clearing. Generic stage diagnostic collection alongside stdout/stderr, with safe bundle-path metadata.
invalidation does not discard checkpoints; reconciliation checks their data. Reuse current manifest-driven diagnostic publication rather than adding a
4. Test round-trip populated and versioned-empty collections, old manifests manifest schema or new publish source IDs. Physical placement does not define
without fields, malformed evidence, deep-copy isolation, and lifecycle canonical artifact identity. Existing diagnostic retention/cleanup rules apply.
preservation. Avoid imposing JSON formatting or map order as contracts.
On failure, retain run-local files and expose the output/report directory in
Verify: `go test ./internal/manifest`. contextual errors. Do not add runner-wide failed-result persistence merely to
register those files. Do not fabricate legacy JSON reports or delete historical
Done when durable storage can represent partial completion independently of reports. Normal successful stage-record replacement removes obsolete current
aggregate status, without activating new stage behavior yet. output references.
## Stage 2: Implement Read-Only Speaker Reconciliation Generated invocation YAML becomes `audita.generated.v2`, recording actual
arguments, selections, paths, and credential names, never values. This remains
Status: Complete. a diagnostic invocation record, not an Audita configuration file.
Completion marker (2026-09-21): Extracted shared deterministic transcribe job ### Resume boundary
construction and added read-only, cancellation-aware per-speaker input and
output reconciliation. Covered unchanged reuse, semantic and operational Bump only polish semantic-config version from 1 to 2. Record config path,
settings, changed/added/removed inputs, legacy and forced work, missing/corrupt overlay/proposal/validation selectors, ordered modules with presence preserved,
outputs, unsafe evidence, and missing audio without connecting runtime skip or transcript description, output schema, and existing output identity. Remove old
checkpoint behavior. Verified with endpoint/model fields. Existing runner comparison reconsiders obsolete evidence
`go test ./internal/stage ./internal/manifest` and `git diff --check`. when polish is selected; do not synthesize equivalent fingerprints or expand
normal dependency/selection invalidation.
Preparation: `internal/stage/transcribe.go`, `semantic_contracts_initial.go`,
`analyze_reconciliation.go`, `extract_resume.go`, their tests, and the artifact Credentials, binary path, timeout, and diagnostics are not semantic keys. Do not
path/integrity helpers they use. hash downstream config/profile contents; operators force polish after edits
behind unchanged selections. Notarius credential migration does not change
1. Extract the existing audio discovery/job construction into a shared, extraction fingerprints, references, force, resume, or chunk-cache behavior.
transcribe-local reconciliation path. Preserve current input selection and
speaker identity behavior. Build sorted jobs and classify completed results ## Stage 1: Adopt ConfigKit v0.4.0 and pipeline overlays
against the current input set and evidence defined above.
2. Add pure fingerprint construction and streamed input/output inspection. Status: Complete (2026-09-25).
Resolve manifest input paths with existing session-relative/absolute reading
helpers; do not change input precedence or assume the current working directory Verification: `go test ./internal/config ./internal/app ./internal/manifest`,
is the session root. Newly written checkpoint paths are always relative. `go test ./...`, `go test ./internal/doccheck`,
3. Return current records and work-to-do without writing files or manifest state. `go test ./internal/config -run '^TestExamplesLoadAndValidate$'`, and
Force selects all work and an empty starting collection; old unversioned `git diff --check` passed.
transcribe state supplies no reusable records. Do not connect aggregate skip
validation until execution can produce the new evidence in Stage 3. Preparation: ConfigKit v0.4.0 release notes and selected-overlay migration guide
4. Test unchanged reuse; one changed audio among unchanged speakers; URL/language in `../ConfigKit/docs/`; Narratio `internal/config/pipeline_configkit.go`,
changes; operational-setting exclusions; added/removed speakers; missing and `artifact_catalog.go`, `load.go`, `effective_digest.go`; CLI flag parsing and
corrupt regular outputs; unsafe record paths; missing audio; and force. config commands in `internal/app/`; configuration provenance in
Prefer compact tables and real temporary files over mocked hashing. `internal/manifest/manifest.go`; current config/CLI docs and pipeline examples.
Verify: `go test ./internal/stage ./internal/manifest`. 1. Update `go.mod`/`go.sum` to ConfigKit v0.4.0 using normal module tooling;
do not leave a local replacement or change unrelated dependencies.
Done when one read-only decision path describes exactly which speakers need Replace removed ConfigKit APIs in loading, ownership, and artifact catalog
work, without altering existing runtime behavior prematurely. inspection. Account for source layer `overlay` and diagnostic prefix
`overlay.*` wherever they are consumed or asserted.
## Stage 3: Execute and Checkpoint Speakers Incrementally 2. Rename Narratio's pipeline selector to `--overlay` across all commands and
aliases, load options, pair loading, inspection, provenance, and tests.
Status: Complete. Preserve explicit-presence handling through convenience commands and existing
base/default selection. Remove `--profile` rather than retaining an alias.
Completion marker (2026-09-21): Connected reconciliation to bounded execution, Apply the selected design's informational manifest-provenance treatment.
durably checkpointed the starting and per-speaker collections through detached 3. Move maintained selected pipeline files and generated fixture paths to
manifest candidates, preserved committed work across failures and cancellation, `overlays/`. Update current canonical documentation, policy terminology,
rebuilt deterministic aggregate outputs from reusable evidence, and added examples, and user-visible migration guidance with the directory/flag break.
speaker-aware resume validation. Updated production-style fixtures and covered Do not rewrite historical release notes, rename downstream model profiles,
serialized concurrent saves, force/retry replacement, input rechecks, save or prohibit ordinary explicit imports from a directory named `profiles`.
failures, partial recovery, and aggregate reconstruction. Verified with 4. Adapt existing config/app tests to prove base and named-overlay selection,
`go test ./internal/stage ./internal/app`, `go test -race ./internal/stage`, and imported defaults plus overrides, secret replacement/removal, source attribution
`git diff --check`. through character-family expansion, config diff, and convenient-command
forwarding. Add focused checks that the retired flag is rejected and the old
Preparation: `internal/stage/transcribe.go`, `analyze_execution_state.go`, directory is not a discovery fallback. Do not freeze incidental error wording.
`run_local.go`, 5. Verify unchanged effective values retain digest and stage-reuse behavior;
`internal/app/runner.go`, and transcribe/checkpoint test fixtures. only diagnostic source labels/paths and selected provenance terminology change.
Test current provenance round trips and strict rejection of unknown/retired
1. Wire reconciliation into Run, require the existing ManifestStore collaborator, provenance fields. Document deliberate operator migration; do not add a
and checkpoint the starting collection before launching HTTP work. Implement compatibility decoder, semantic invalidation rule, or schema-version gate.
detached candidate saves and serialized live-state updates. Audit Store.Save's 6. Run focused and full tests before proceeding so failures from the dependency
normalization side effects so a failed candidate save cannot mutate shared and terminology change are separated from adapter migrations. No Audita or
authority; use detached records/collections wherever it may write. Notarius credential/CLI behavior changes in this stage.
2. Retain bounded errgroup execution and fail-fast cancellation. Check the work
context before beginning each queued request. After success, validate adapter Verify: `go test ./internal/config ./internal/app ./internal/manifest`,
output path/JSON, recheck audio evidence, materialize canonical bytes, compute `go test ./...`, `go test ./internal/doccheck`,
output evidence, and checkpoint the new record. Check a checkpoint-failure
latch under the serialization lock before accepting further completions.
3. Preserve committed successes on all error/cancellation exits, including
starting-save, canonical-write, per-speaker-save, and aggregate-save failures.
Return meaningful speaker/error context and let the runner retain its existing
terminal failure behavior. Do not report partial aggregate outputs as success.
4. Assemble final outputs in deterministic speaker order from the reconciled
completed records, including reused speakers, with original producer IDs and
checksums. If all records are current but aggregate status is failed/running,
finish without WhisperX calls and rebuild the aggregate success.
5. Implement `transcribeStage.ValidateResume` using the same read-only
reconciliation, so a succeeded stage cannot skip changed audio or invalid
transcripts. Retain the existing URL/language semantic check and runner
invalidation behavior; no whole-config digest invalidation.
6. Adapt existing tests that require no canonical partial files: the new contract
permits checkpointed files but forbids aggregate success. Update fixtures to
provide real manifest stores and records rather than a production fallback
that silently disables checkpointing.
7. Test A/B completion followed by C failure and D unattempted (concurrency 1),
reload and retry only C/D; concurrently finishing speakers without lost saves;
failure and cancellation after a checkpoint; save failure retaining earlier
authority; and force failure followed by ordinary retry without old-result reuse.
Verify: `go test ./internal/stage ./internal/app` and
`go test -race ./internal/stage`.
Done when incremental progress and aggregate success work together safely under
ordinary, concurrent, canceled, and forced execution.
## Stage 4: Verify Runner, Merge, and Durable Lifecycle Integration
Status: Complete.
Completion marker (2026-09-22): Added real-persistence application coverage for
cross-invocation retry, interrupted running state, failed aggregate saves,
force/reset persistence, downstream invalidation, and one-time legacy upgrade.
Versioned merge input discovery now requires aggregate success and an exact
match between current speaker evidence and declared aggregate outputs, while
legacy/manual directory fallback remains available. Restore coverage preserves
session-relative speaker paths, leaves unpublished raw transcripts absent, and
canonical transcripts remain reusable after run-directory cleanup. Verified
with `go test ./internal/app ./internal/stage ./internal/manifest`,
`go test -race ./internal/app`, and `git diff --check`.
Preparation: `internal/app/runner.go`, `runner_runtime.go`,
`analyze_checkpoint_recovery_test.go`, `runner_terminal_failure_test.go`,
`restore_manifest_paths.go`, `internal/stage/merge.go`, and existing publish,
restore, and cleanup tests routed from `docs/internal/overview.md`.
1. Add application-level tests with real manifest persistence and fake WhisperX:
failed stage across separate invocations; all speakers committed before a
failed aggregate save; interrupted running state; force/reset persistence;
and unchanged upstream/succeeded downstream invalidation behavior. Inject
errors at durable boundaries, not every private method call.
2. Close `discoverRawTranscripts`' directory-scan fallback for versioned
transcribe state: incomplete aggregate state is not usable, and completed
state consumes only declared current aggregate outputs. Keep legacy/manual
fallback behavior for manifests without the new state rather than banning
previously allowed standalone workflows. Test that partial files and removed
speaker files cannot leak into a versioned merge, including direct stage calls.
3. Audit manifest copies/projections, remote manifest publication, restored path
handling, and cleanup. Preserve relative speaker paths on restore and verify
they resolve under the destination session, not the producer machine. Reuse
existing confinement validation, not a second path-policy layer.
4. Add focused round-trip coverage through existing publish/restore fixtures for
speaker records. Restored outputs absent from the published selection are
non-reusable locally; do not silently expand remote publication to every raw
speaker or upload audio as a new default. Removing run directories must not
remove canonical checkpointed transcripts or make reuse require run files.
5. Verify old succeeded manifests are readable and rerun once when transcribe is
selected, then reuse normally. Keep old manifests usable for other commands
and bounded ranges. Do not automatically import old unrecorded JSON files.
Verify: `go test ./internal/app ./internal/stage ./internal/manifest` and
`go test -race ./internal/app`.
Done when the new authority survives runner and storage lifecycles and cannot
expose incomplete transcripts downstream.
## Stage 5: Implement Replayable Streaming Multipart Bodies
Status: Complete.
Completion marker (2026-09-22): Replaced the producer-goroutine/pipe upload
with bounded standard-library multipart framing and independently opened,
pull-based streaming bodies shared by the initial request and `GetBody`.
Bodies are tracked, idempotently closed, canceled with their attempt context,
and retain genuine read/close failures without treating an intentionally
abandoned original as a replay failure. Added focused coverage for identical
framing, partial-read restart, simultaneous handles, source failures, and
blocked-reader release. Verified with `go test ./internal/adapters/whisperx`,
`go test -race ./internal/adapters/whisperx` (including ten repeated runs), and
`git diff --check`.
Preparation: `internal/adapters/whisperx/http.go`, `http_test.go`,
`docs/integrations/whisperx.md`, and the installed Go net/http Request/GetBody
contract. Keep this change inside the WhisperX adapter.
1. Implement the pull-based framing/body factory described above, using standard
multipart encoding rather than hand-escaped MIME headers. Add no new payload
cap or upload-size setting. Preserve file-before-language wire semantics and
the existing form names.
2. Install the initial body and GetBody with the same per-attempt boundary.
Track and close all opened bodies even if a custom transport returns early;
make cleanup/context callbacks safe against overlapping reads and closes.
A GetBody failure must be returned, not converted into an empty upload.
3. Replace pipe-specific Wait/error paths in doTranscribeAttempt with source-error
handling appropriate to pull bodies. Genuine source errors remain visible;
intentional closure during transport retry is not itself a source error.
Keep response bounds, JSON validation, output installation, retry
classification/delay, cancellation, and application attempt reporting intact.
4. Remove obsolete producer-only helpers rather than retaining two upload paths.
Adapt tests tied to producer goroutines to assert streaming and resource
release, which are the actual contracts.
5. Add focused body tests: original/replayed bytes parse identically; replay
after partial consumption starts from the beginning; simultaneous bodies use
independent handles; source failures propagate; Close/cancel releases a
blocked reader without deadlock. Use synthetic audio and gated readers.
Verify: `go test ./internal/adapters/whisperx` and
`go test -race ./internal/adapters/whisperx`.
Done when replay is available without whole-file buffering or producer-lifetime
ambiguity, and all existing HTTP behavior tests still pass.
## Stage 6: Verify Replay Through the HTTP Adapter Boundary
Status: Complete.
Completion marker (2026-09-22): Added a deterministic transport regression
that abandons a partially consumed original request, obtains and parses a fresh
multipart replay from `GetBody`, and installs the returned transcript within one
application attempt. Covered replay open/read failures, early responses,
parent cancellation during replay, and disposal of every opened source, while
proving an abandoned original does not poison a valid replay. Added a real HTTP
retry-exhaustion integration that durably retains an earlier speaker and resumes
only the uncommitted speakers. This controlled boundary verifies Narratio's
replay contract, not recovery from every real proxy protocol failure. Verified
with `go test ./internal/adapters/whisperx ./internal/app ./internal/stage`,
`go test -race ./internal/adapters/whisperx ./internal/app ./internal/stage`,
ten repeated race-enabled adapter runs, and `git diff --check`.
Preparation: Existing injectable HTTPClient/RoundTripper seam and local-server
tests in `internal/adapters/whisperx/http_test.go`; app WhisperX wiring tests.
1. Add a deterministic transport-boundary regression: consume part of the
original request, close it as a transport would, call GetBody, consume and
parse the replay using the request Content-Type, then return valid JSON.
Verify exact audio/language, installed output, and one application attempt.
This must fail before replay support; merely checking non-nil GetBody is
insufficient. Do not assert Go's internal retry count or require a flaky
handcrafted HTTP/2 peer in the default suite.
2. Cover replay-open/read failure, early response, parent cancellation during
replay, and disposal of all body handles. Reuse Stage 5 body coverage rather
than repeat every low-level case. Prove an intentionally abandoned original
body does not turn a valid replay response into failure.
3. Retain local HTTP tests for application retries, non-retryable responses,
response limits, invalid JSON, and bounded streaming; exercise that an
exhausted HTTP failure still leaves earlier speaker checkpoints reusable
using the existing stage/app seams.
4. Record the verification boundary honestly: controlled transport replay proves
Narratio's body contract, not recovery from every real proxy PROTOCOL_ERROR.
Verify: `go test ./internal/adapters/whisperx ./internal/app ./internal/stage`
and race tests for changed packages.
Done when the replay defect is protected at the adapter boundary and the
application retry/checkpoint behavior remains intact.
## Stage 7: Document and Validate the Completed Feature
Status: Complete.
Completion marker (2026-09-22): Updated the canonical transcribe, merge,
manifest, WhisperX, operations, and troubleshooting documentation for durable
speaker reconciliation, serialized checkpoints, aggregate gating, durable
force reset, legacy upgrade and downgrade limits, replayable streaming bodies,
resource ownership, and the absence of an exactly-once remote guarantee.
Reviewed the completed implementation against the feature roadmap and
implementation-discipline guidance. Verified with `go test ./...`,
`go test -race ./...`, `go vet ./...`, `go build ./...`,
`go test ./internal/doccheck`,
`go test ./internal/config -run '^TestExamplesLoadAndValidate$'`, and `go test ./internal/config -run '^TestExamplesLoadAndValidate$'`, and
`git diff --check`. `git diff --check`.
1. Update canonical transcribe and manifest internals for the collection, Done when Narratio uses ConfigKit v0.4.0, exposes pipeline overlays consistently,
reconciliation, durable-reset force behavior, serialized saves, and aggregate has no old selector/directory fallback, and preserves configuration semantics and
gate. Remove obsolete all-speakers-before-canonical-write descriptions. downstream model-profile concepts.
2. Update the WhisperX contract for replayable bounded streaming, application
attempts versus transport replay, resource ownership, and the lack of an ## Stage 2: Add shared resolved-credential forwarding
exactly-once server guarantee. Do not claim the remote protocol issue is fixed.
3. Update operations/troubleshooting with ordinary resume versus force, durable Status: Complete (2026-09-25).
partial success, old-manifest one-time retranscription on selecting transcribe,
downgrade limitations, and private-model-change guidance. No new CLI flags Verification: `go test ./internal/adapters/subprocess`,
or promises of automatic historical-file recovery. Keep detailed wire and `go test -race ./internal/adapters/subprocess`, and `git diff --check` passed.
storage contracts in their canonical owners.
4. Review changes against the feature roadmap and the implementation-discipline Preparation: `internal/adapters/subprocess/run.go`, its environment/redaction
guidance. Do not elevate selected storage encoding, internal ordering, test helpers and tests; `internal/adapters/notarius/subprocess.go`;
synchronization, or exact error wording into new product guarantees. `internal/config/credential_projection.go`; the pinned ConfigKit secret API.
5. Run the full repository gates below; document results and update completion
statuses only after they pass. Leave release preparation for a separate task. 1. Add the narrow helper described above. Return an independent environment map
and selected sensitive names. No logging/serialization of values and no
changes to minimal child environment inheritance.
2. Test multiple custom names, empty lists, repeated names, unresolved references,
and captured values after the parent environment changes. Reuse existing
split/overlapping-stream redaction coverage rather than repeating its matrix.
3. Leave production callers unchanged until their migrations.
Verify: `go test ./internal/adapters/subprocess` and
`go test -race ./internal/adapters/subprocess`.
Done when both adapters can reuse one small conversion mechanism without adding
a resolver, provider policy, or ambient-secret inheritance.
## Stage 3: Migrate Notarius to credential lists
Status: Complete (2026-09-25).
Verification: `go test ./internal/config ./internal/adapters/notarius ./internal/stage ./internal/app`,
`go test -race ./internal/adapters/notarius`, and `git diff --check` passed.
Preparation: `internal/config/config.go`, `credential_projection.go`, loading/
inspection tests; `internal/adapters/notarius/runner.go`, `subprocess.go`;
`internal/stage/extract.go` and its request construction;
`docs/integrations/notarius.md` and secret handling in `docs/config.md`.
1. Replace the singular field with the typed list across configuration,
projection, request types, stage wiring, and adapter execution. Use Stage 2's
helper and register all selected names for redaction.
2. Update name-only metadata and config-show/diff/effective projections. Test
real ConfigKit loading, overlay list replacement, and empty-list clearing.
Preserve bootstrap precedence and existing load-time reference resolution,
including references outside the selected stage range.
3. Migrate maintained examples, fixtures, and current Notarius configuration/
integration documentation for this field. Ordinary strict decoding rejects
the old field; do not add a compatibility parser.
4. Cover multi-key forwarding, unselected-key exclusion, empty selection,
captured-value behavior, and custom-name redaction on success/failure.
Keep extraction cache/reference/output tests as regression protection,
not occasions to redesign extraction.
Verify: `go test ./internal/config ./internal/adapters/notarius ./internal/stage ./internal/app`
and `go test -race ./internal/adapters/notarius`.
Done when Notarius uses credential lists end to end and no active singular
credential path remains.
## Stage 4: Cut Audita configuration and adapter over to v2
Status: Complete (2026-09-25).
Verification: `go test ./internal/config ./internal/adapters/audita ./internal/stage ./internal/app`,
`go test -race ./internal/adapters/audita`, `go test ./...`, and
`git diff --check` passed.
Preparation: Audita v2.0.0 `docs/migrations/v2.md`, `docs/cli.md`,
`docs/integrations/subprocess.md`, and `docs/integrations/output-files.md` in
`../audita/`; Narratio `internal/adapters/audita/`,
`internal/app/runner.go` (`buildDefaultAuditaRunner`), and config types,
defaults, validation, and credential projection.
1. Replace the Audita configuration surface as selected above, updating defaults,
validation, safe projection, examples, and config fixtures. Prove nil/empty
modules survive real configuration loading and overlay overrides.
2. Migrate runner construction, selectors, and credential forwarding. Remove
retired flags, fixed credential alias, required work-directory plumbing, and
old JSON-report validation. Add the typed report bundle.
3. Implement adjacent report discovery, bounded reads, failure results, and
generated invocation v2. Share metadata construction between success/failure
instead of maintaining duplicate field maps.
4. Rewrite the Audita subprocess fixture to model v2 argument acceptance and
output placement. Cover omitted/selected selectors, ordered/repeated/empty
modules, no report/debug switches, malformed/missing transcript, ordinary
reports, externally disabled reporting, recoverable-error success, and
nonzero exit after transcript creation. Cover multiple custom credential names
and redaction; preserve timeout/cancellation coverage at its existing owner.
5. Make mechanical polish and app-fixture adjustments needed to compile: remove
obsolete request/metadata fields and old report materialization. Stage 5 owns
complete diagnostic integration. Remove retired fingerprint members as needed
to compile; Stage 6 completes the replacement semantic contract. These are
bounded call-site changes, not permission to introduce transitional shims.
Verify: `go test ./internal/config ./internal/adapters/audita ./internal/stage ./internal/app`
and `go test -race ./internal/adapters/audita`.
Done when configuration composes a v2-only adapter and subprocess tests prove its
credential/transcript/report boundary. Stages 5 and 6 complete diagnostic and
semantic integration; all stages are required before release.
## Stage 5: Integrate polish reports with diagnostic lifecycle
Status: Complete (2026-09-25).
Verification: `go test ./internal/stage ./internal/app ./internal/manifest ./internal/artifacts`,
`go test -race ./internal/stage ./internal/app`, and `git diff --check` passed.
Preparation: `internal/stage/polish.go`, `polish_test.go`, `run_local.go`,
`stage.go`, `publish_sources.go`; result application in `internal/app/runner.go`;
publish/restore diagnostic tests; `docs/internal/stage-polish.md`.
1. Finish stage integration: materialize only the canonical polished transcript;
register available adjacent reports as diagnostics plus safe metadata and
existing logs/generated invocation references. Remove old `audita_report`
production and stale stage metadata.
2. Use existing authoritative-path checks for the requested transcript and fixed
adjacent report paths. Do not accept arbitrary fake-returned paths, scan
directories, or copy reports to a second destination. Preserve workspace
handling/modes.
3. On execution failure, preserve canonical transcript authority and run-local
diagnostics, with actionable directory/log context and original error identity.
Test failure after output creation.
4. Adapt the fake and app helper. With real manifest/store collaborators, prove
successful promotion, report references, absence of report canonical outputs,
and current-run diagnostic publication. Preserve restore's existing scope of
declared committed transcript/artifact objects: run-archive diagnostics do not
become automatically restored canonical objects. Test that report references
do not create new required canonical restore targets. Document remote diagnostic
inspection separately; no new diagnostic-restore feature is authorized.
5. Leave historical files untouched. Update tests expecting a second canonical
polish output without introducing a manifest-format migration.
Verify: `go test ./internal/stage ./internal/app ./internal/manifest ./internal/artifacts`
and `go test -race ./internal/stage ./internal/app`.
Done when reports use existing diagnostic lifecycle and failed execution cannot
promote an incidental transcript.
## Stage 6: Complete semantic evidence and resume behavior
Status: Complete (2026-09-25).
Verification: `go test ./internal/stage ./internal/app`,
`go test -race ./internal/stage ./internal/app`, and `git diff --check` passed.
Preparation: `internal/stage/semantic_contracts_refinement.go`, semantic
fingerprint tests, app runner semantic comparison tests, and extraction semantic
configuration tests (locate their current owners through graph discovery).
1. Implement polish evidence version 2 and the selected payload. Remove sorting;
preserve nil/empty distinction in payload encoding and copies.
2. Test changes from module order/repetition/presence and external selectors.
Credentials and execution-only settings do not change evidence. Avoid
assertions on incidental digest literals.
3. Exercise old-version evidence through runner resume behavior: selected polish
is reconsidered and normal dependent invalidation applies. Downstream-only
bounded execution does not unexpectedly invoke polish. Unchanged new evidence
reuses valid completed output.
4. Confirm credential-list changes leave extraction semantic/cache behavior
unchanged. No downstream file-content scanning or eager fingerprint migration.
Verify: `go test ./internal/stage ./internal/app` and
`go test -race ./internal/stage ./internal/app`.
Done when selections affect reuse accurately without blanket credential/config
invalidation or changes to unselected-stage execution.
## Stage 7: Complete operator migration documentation and examples
Status: Complete (2026-09-25).
Verification: `go test ./internal/doccheck`,
`go test ./internal/config -run '^TestExamplesLoadAndValidate$'`, and
`git diff --check` passed.
Preparation: documentation policy; `docs/config.md`, `docs/operations.md`,
`docs/troubleshooting.md`, both integration guides,
`docs/internal/adapters.md`, `docs/internal/stage-polish.md`, and pipeline examples.
1. Complete current-behavior documentation as implementation lands. Configuration
owns fields/defaults; integrations own external contracts; operations owns
placement and migration; internal docs explain ownership and link onward.
2. Provide an old-to-new migration table: endpoints/capacity move to Audita
backends, models to profiles, role selection to selectors, and credentials to
provider-named lists. Remove report/retention settings. Explain Audita's
all-configured-backend credential resolution and Notarius's profile lookup.
3. Describe preparing and validating Audita v2 config offline with its documented
command before switching executables. Link upstream examples rather than
building a downstream configuration generator. Explain ordinary reports,
recoverable-error success, and force after edits behind unchanged selectors.
4. Production examples omit modules when upstream defaults are intended;
`modules: []` deliberately disables correction modules. Production external
Audita config keeps reports enabled/debug disabled, without Narratio flag
overrides. Testing-profile debug integration remains deferred.
5. Document the configuration-breaking clean cutover for release-version
consideration. Do not edit historical release records, tag a release, or
remove unrelated roadmaps.
Verify: `go test ./internal/doccheck`,
`go test ./internal/config -run '^TestExamplesLoadAndValidate$'`, and
`git diff --check`.
Done when operators can migrate using valid examples without obsolete fields,
implicit credential aliases, or retired CLI/report expectations.
## Stage 8: Verify assembled behavior and audit scope
Status: Complete (2026-09-25).
Verification: the offline app-level shared/Audita-only credential scenario
passed with config bootstrap, both subprocess fixtures, safe inspection/logging,
and ordinary polish reports. The tagged Audita v2.0.0 CLI validated its minimal
configuration and produced a transcript plus all three reports with an empty
module sequence and no provider request. Active-reference and scope audits found
no removed production fields or compatibility path; remaining old names occur in
migration guidance, explicit-rejection checks, or historical fixtures. `go test
./...`, `go test -race ./...`, `go vet ./...`, `go build ./...`, `go test
./internal/doccheck`, `go test ./internal/config -run
'^TestExamplesLoadAndValidate$'`, and `git diff --check` passed.
Preparation: cumulative diff, this plan, feature roadmap, app configuration/
subprocess integration tests, and all policies.
1. Adapt or add one representative offline app-level scenario showing one
provider-named secret source supplying both adapters and another key selected
only for Audita. Use real config/bootstrap/composition with subprocess fixtures.
Prove safe inspection/logging and successful polish reports. Leave exhaustive
flag/redaction cases at lower layers.
2. Where the tagged Audita checkout is available, smoke-test CLI acceptance and
ordinary transcript/reports offline with an explicit minimal v2 config,
unauthenticated backend/profile fixtures, and an empty module sequence.
No provider requests or production credentials. This is optional local evidence,
not a default test dependent on sibling checkouts or installed tools.
3. Audit active references to removed fields/flags/aliases; historical release
notes and completed roadmaps are not compatibility code. Review tests
collectively for duplication while retaining consequential failure coverage.
4. Confirm no provider-name restrictions, duplicate-name rejection, downstream
content hashing, fail-on-recovery rule, mandatory explicit config path, debug
requirement, live-service gate, pipeline-order change, or Notarius cache change
slipped in. Do not require missing reports when disabled externally. Surface
additional policy choices rather than encoding them silently in tests.
5. Run every gate below and record actual results. Mark complete only after all
stages and gates pass. No release, tag, push, or unrelated cleanup in this plan.
```sh ```sh
go test ./... go test ./...
@@ -422,10 +471,12 @@ go test ./internal/config -run '^TestExamplesLoadAndValidate$'
git diff --check git diff --check
``` ```
Done when the assembled v2 integration and shared credentials meet the roadmap,
verification passes, and no compatibility machinery remains within scope.
## Open Questions ## Open Questions
None requiring user input. The agreed roadmap supplies the product decisions; None requiring a product decision before implementation. The user settled the
this plan selects a completed-only manifest collection, conservative old-record clean cutover and shared provider-named lists. Reports use existing diagnostics
handling, and pull-based replay as implementation choices. No stronger remote without new content-based success criteria; debug-profile work remains deferred.
reliability guarantee, new operator restriction, or generic orchestration Release version selection belongs to the later release procedure.
surface is proposed.

View File

@@ -1,4 +1,127 @@
# Transcription Checkpoint Review Remediation # Audita v2 and ConfigKit Migration Review Remediation
Status: Complete.
Reviewed `83eaa96` through `fae18bf` against the approved clean-cutover decisions,
[feature roadmap](audita.md), and [implementation plan](implementation.md).
Review date: 2026-09-25. No production changes were made. The previous completed
transcription review is retained below as historical context.
## 1. Preserve omitted modules in direct YAML serialization
Priority: P2. Status: Complete.
The safe YAML projection now omits nil modules while retaining explicit empty
and ordered/repeated selections. A round-trip regression failed before the fix
and passes afterward. Config package tests, including credential-safety coverage,
and its race tests pass.
Location: `internal/config/credential_projection.go:25` (`AuditaConfig.MarshalYAML`),
especially the plain slice field at line 30 and assignment at line 40.
The direct safe YAML projection passes a nil module slice to yaml.v3, which
serializes it as `modules: []`. Loading that output produces a non-nil empty
slice. Under the new Audita contract these are different instructions: nil
delegates to Audita's configuration/default sequence; empty passes an explicit
empty module argument and disables correction modules. Serialization therefore
silently changes behavior for a configuration that is subsequently reloaded.
Evidence: a temporary package test marshaled
`AuditaConfig{Binary: "audita", Timeout: "3h"}`, unmarshaled it into another
`AuditaConfig`, and required `Modules == nil`. It failed with output containing
`modules: []`. The test was removed after reproduction. This concerns direct
`yaml.Marshal` of the typed configuration; ordinary CLI `config show` uses
`MarshalEffectivePipeline` through a separate JSON/value-tree projection and
does not use this faulty path.
Required remediation:
- Make the direct safe YAML projection preserve nil as null or omission and
explicit empty as `[]`. Do not simply add `omitempty` to the slice: that would
instead erase the explicit empty selection.
- Keep credential serialization name-only and preserve module order/repetitions.
- Add a small round-trip regression covering nil, explicit empty, and an ordered
repeated selection; retain effective-output inspection coverage without
duplicating its whole test matrix.
## 2. Remove the unapproved manifest compatibility decoder
Priority: P2. Status: Complete.
Removed the permissive custom decoder; ordinary strict typed decoding now
applies to provenance as well. Replaced historical-acceptance coverage with
retired/unknown-field rejection tests, all of which failed before removal.
Current provenance round-trip coverage remains intact. Corrected the roadmap,
plan, internal contract, and operator guidance for narrow backed-up migration
without discarding execution/checkpoint state or changing resume authority.
Location: `internal/manifest/manifest.go:79-89`,
`internal/manifest/store_test.go:78`, and `docs/internal/manifest.md`'s decoding
contract. Also correct the conflicting migration language in the plan/roadmap.
The new `EffectiveConfigProvenance.UnmarshalJSON` bypasses the manifest store's
`DisallowUnknownFields` by using permissive `json.Unmarshal` for the entire
provenance object. It accepts retired `selected_profile` data and silently
discards it. It also silently accepts unknown current provenance fields,
including unknown nested selection fields, rather than limiting behavior to
the renamed label.
The user expressly selected a clean cutover without backward-compatibility
shims. This adds precisely such a shim and a new historical-input acceptance
guarantee. The regression test explicitly requires the old selection to load,
and the internal guide now declares permissive informational-field decoding.
The plan contributed to this divergence: it said existing generic decoding
would handle historical optional provenance and required old manifests to load.
That assumption was false; the baseline store already strictly decoded these
fields. Repetition in the plan, tests, and documentation does not authorize
overriding the user's clean-cutover decision.
Required remediation:
- Remove the custom compatibility unmarshaler and retain ordinary strict typed
decoding for the new `selected_overlay` representation. Do not add dual fields,
special retired-field handling, automatic manifest rewrites, or a format-version
bump just for this rename.
- Replace the historical-acceptance test with coverage for current provenance
round trips and unknown/retired provenance rejection through the real store.
- Correct the plan and current documentation to acknowledge the upgrade effect:
manifests with retired provenance require deliberate operator migration before
loading. Document narrow removal/renaming of retired informational provenance
on a backed-up manifest, preserving execution/checkpoint state; do not advise
deleting all session progress or rerunning everything.
- Keep provenance informational: this correction does not authorize adding it
to semantic resume keys or invalidating work based on overlay identity alone.
If transparent historical-manifest acceptance is desired instead, obtain an
explicit exception to the clean-cutover decision before retaining a compatibility
reader. Do not treat that exception as already granted.
## Review verification
The following records the original review, before remediation.
- Existing `go test ./...` passed.
- Race tests passed for subprocess, Audita, Notarius, config, stage, app, and
manifest packages after removing the temporary reproduction.
- `go vet ./...` passed.
- The temporary direct-YAML regression failed as described above.
- Source inspection and the new historical-provenance test establish finding 2;
`LocalStore.LoadReader` still uses strict decoding outside the custom hook.
The primary architecture is otherwise in place: ConfigKit v0.4.0 overlays,
shared named credential forwarding/redaction, a v2-only Audita subprocess
adapter, ordinary reports as diagnostics, and versioned ordered-module polish
evidence. No live model/provider runs were performed during this review.
## Migration remediation verification
Completed on 2026-09-25. Both new regressions failed before their respective
fixes. After remediation, `go test ./...`, `go test -race ./...`,
`go vet ./...`, `go build ./...`, documentation checks, maintained configuration
example checks, and `git diff --check` passed. No live provider runs were needed.
## Historical completed transcription review
Status: Complete. Status: Complete.
@@ -7,7 +130,7 @@ upload-replay roadmap and the original user request. No production changes were
made during review. The two failures below were reproduced with temporary tests made during review. The two failures below were reproduced with temporary tests
using the existing stage fixtures; those temporary tests were removed afterward. using the existing stage fixtures; those temporary tests were removed afterward.
## 1. Reconcile Aggregate State Even When No Speaker Needs HTTP Work ### 1. Reconcile Aggregate State Even When No Speaker Needs HTTP Work
Priority: P2. Status: Complete. Priority: P2. Status: Complete.
@@ -54,7 +177,7 @@ an added speaker), plus incomplete/inconsistent aggregate output coverage.
Exercise the runner skip path and assert zero additional WhisperX requests, Exercise the runner skip path and assert zero additional WhisperX requests,
correct rebuilt outputs, and no removed speaker reaching merge. correct rebuilt outputs, and no removed speaker reaching merge.
## 2. Remove the Unrequested Positive Audio-Size Requirement ### 2. Remove the Unrequested Positive Audio-Size Requirement
Priority: P2. Status: Complete. Priority: P2. Status: Complete.
@@ -94,7 +217,7 @@ Verification: cover a zero-size record round-trip and successful adapter result
being checkpointed/reused for that input; retain negative-size rejection and being checkpointed/reused for that input; retain negative-size rejection and
ordinary downstream-failure tests. ordinary downstream-failure tests.
## Verification After Remediation ### Verification After Remediation
Completed on 2026-09-22 with Go 1.26.8: focused stage/application tests, Completed on 2026-09-22 with Go 1.26.8: focused stage/application tests,
changed-package race tests, `go test ./...`, `go test -race ./...`, changed-package race tests, `go test ./...`, `go test -race ./...`,

View File

@@ -15,9 +15,9 @@ peer `PROTOCOL_ERROR` and an inability to replay the request body without
`Request.GetBody`. `Request.GetBody`.
These are related reliability improvements, not a promise to eliminate all These are related reliability improvements, not a promise to eliminate all
service failures. This document owns the target state and scope; the service failures. This document records the target state and scope. The
[implementation plan](implementation.md) owns ordered changes and concrete completed implementation sequence is retained in Git history; current behavior
storage and replay decisions. is documented in the canonical guides linked below.
## Pre-implementation Limitations ## Pre-implementation Limitations

View File

@@ -102,7 +102,7 @@ Safe fix:
Relevant reference: [Canonical Party Input](./integrations/party.md). Relevant reference: [Canonical Party Input](./integrations/party.md).
## Unexpected imported or profile value ## Unexpected imported or overlay value
Symptom: Symptom:
@@ -112,21 +112,21 @@ Symptom:
Diagnostics: Diagnostics:
```bash ```bash
narratio config sources --config /path/pipeline.yml --profile testing narratio config sources --config /path/pipeline.yml --overlay testing
``` ```
Add `--campaign` or `--campaign-file` when the pipeline has party-driven Add `--campaign` or `--campaign-file` when the pipeline has party-driven
artifact families. The output identifies each effective logical field's root, artifact families. The output identifies each effective logical field's root,
import, profile, default, campaign, party, or family source without printing import, overlay, default, campaign, party, or family source without printing
the field value or credential contents. the field value or credential contents.
Safe fix: Safe fix:
- move a duplicated base field so it has one owner; - move a duplicated base field so it has one owner;
- correct the selected profile or its overlay; or - correct the selected overlay; or
- correct the campaign party/family declaration that owns generated values. - correct the campaign party/family declaration that owns generated values.
To review what would actually change before switching profiles, run `config To review what would actually change before switching overlays, run `config
diff` with the same pipeline and campaign selectors. It compares normalized diff` with the same pipeline and campaign selectors. It compares normalized
effective values rather than YAML formatting or source-file layout. effective values rather than YAML formatting or source-file layout.
@@ -312,7 +312,7 @@ and [Transcribe internals](./internal/stage-transcribe.md).
Symptom: Symptom:
- configuration loading reports `secret.unset`, `secret.empty`, or an invalid - configuration loading reports `secret.unset`, `secret.empty`, or an invalid
name for `pipeline.notarius.llm_api_key`, including during inspection or a name in `pipeline.notarius.credentials`, including during inspection or a
run that would not execute extraction. run that would not execute extraction.
Likely causes: Likely causes:
@@ -328,7 +328,7 @@ Safe fix:
- set the exact nonempty environment variable or provide an equivalently named - set the exact nonempty environment variable or provide an equivalently named
file through the conventional or explicit secrets directory; file through the conventional or explicit secrets directory;
- remove or set the field to `null` when that deployment needs no credential; - remove, set to `null`, or set to `[]` when that deployment needs no credential;
and and
- use `config show`, `config sources`, and `config diff` to inspect the public - use `config show`, `config sources`, and `config diff` to inspect the public
reference name and ownership without exposing its value. reference name and ownership without exposing its value.
@@ -339,7 +339,43 @@ invalidate a completed extraction, but the current reference must still resolve
for the command to proceed. for the command to proceed.
Relevant references: [Secrets](./config.md#secrets-handling) and Relevant references: [Secrets](./config.md#secrets-handling) and
[Notarius credential](./config.md#notarius-credential). [Notarius credentials](./config.md#notarius-credentials).
## Audita v2 configuration or credential failure
Symptom:
- Narratio rejects a retired `pipeline.audita` field during loading, reports
`secret.unset` or `secret.empty` for a listed credential, or Audita rejects
its external configuration or selected profile when polish runs.
Likely causes:
- the Narratio pipeline still uses v1 endpoint, model, capacity, singular key,
report, or retention settings;
- the named key is missing or empty, including a present but empty process
environment variable that takes precedence over a secrets-directory file;
- Audita's external v2 file references a backend credential name not forwarded
by `pipeline.audita.credentials`, including a backend not selected by the
current profile; or
- an Audita overlay or profile selector names a missing downstream definition.
Safe fix:
- follow the [migration table](./operations.md#migrating-audita-and-provider-credentials)
and use a supported Audita v2 executable and configuration;
- provide each needed provider-named variable through the environment or
secrets directory, and list that same name in `pipeline.audita.credentials`;
- validate the external file offline with
`audita config validate --config <file>` before switching executables; and
- inspect Audita's effective profile selection separately from Narratio's
`config show`. Narratio does not infer downstream selectors.
An exit-zero polish with a valid transcript succeeds even when Audita reports
recoverable errors or no corrections. Missing reports are allowed when Audita
reporting is disabled externally. Edits to Audita-owned files behind unchanged
selectors require `narratio run-stage polish <session-id> --force` to replace a
previously successful result. See the [Audita integration contract](./integrations/audita.md).
## Notarius executable missing ## Notarius executable missing

View File

@@ -14,16 +14,16 @@ in the [configuration reference](../docs/config.md).
- [Production-base/testing-overlay bundle](production-testing/pipeline.yml): - [Production-base/testing-overlay bundle](production-testing/pipeline.yml):
explicit `conf.d` imports, one ordinary artifact per `artifacts/<key>.yml`, explicit `conf.d` imports, one ordinary artifact per `artifacts/<key>.yml`,
one family per `artifact-families/<key>.yml`, and the fixed one family per `artifact-families/<key>.yml`, and the fixed
`profiles/testing.yml` overlay. Production values live in the base. The `overlays/testing.yml` overlay. Production values live in the base. The
bundle demonstrates an input-only artifact dependency, two character families bundle demonstrates an input-only artifact dependency, two character families
sharing the campaign party, and a testing-only disabled artifact. Inspect it sharing the campaign party, and a testing-only disabled artifact. Inspect it
offline with: offline with:
```sh ```sh
narratio config validate --config examples/production-testing/pipeline.yml --campaign-file examples/campaigns/sample-campaign/campaign.yml narratio config validate --config examples/production-testing/pipeline.yml --campaign-file examples/campaigns/sample-campaign/campaign.yml
narratio config show --config examples/production-testing/pipeline.yml --campaign-file examples/campaigns/sample-campaign/campaign.yml --profile testing narratio config show --config examples/production-testing/pipeline.yml --campaign-file examples/campaigns/sample-campaign/campaign.yml --overlay testing
narratio config sources --config examples/production-testing/pipeline.yml --campaign-file examples/campaigns/sample-campaign/campaign.yml --profile testing narratio config sources --config examples/production-testing/pipeline.yml --campaign-file examples/campaigns/sample-campaign/campaign.yml --overlay testing
narratio config artifacts --config examples/production-testing/pipeline.yml --campaign-file examples/campaigns/sample-campaign/campaign.yml --profile testing narratio config artifacts --config examples/production-testing/pipeline.yml --campaign-file examples/campaigns/sample-campaign/campaign.yml --overlay testing
narratio config diff default testing --config examples/production-testing/pipeline.yml --campaign-file examples/campaigns/sample-campaign/campaign.yml narratio config diff default testing --config examples/production-testing/pipeline.yml --campaign-file examples/campaigns/sample-campaign/campaign.yml
``` ```
@@ -70,7 +70,11 @@ The examples contain environment-variable names but no credential values. Set
`OBJECT_STORAGE_KEY_ID`, `OBJECT_STORAGE_KEY`, `AUDITA_LLM_API_KEY`, and `OBJECT_STORAGE_KEY_ID`, `OBJECT_STORAGE_KEY`, `AUDITA_LLM_API_KEY`, and
`NOTARIUS_LLM_API_KEY` to nonempty synthetic or real values before loading the `NOTARIUS_LLM_API_KEY` to nonempty synthetic or real values before loading the
examples that reference them. They use fictional campaign content and reserved examples that reference them. They use fictional campaign content and reserved
example domains. example domains. The Audita and Notarius names are example references, not
implicit aliases: external backend/profile configurations must use those exact
names, or the Narratio credential lists must be changed to match. See the
[Audita v2 migration guide](https://gitea.maximumdirect.net/eric/audita/src/tag/v2.0.0/docs/migrations/v2.md)
for maintained downstream configuration examples.
For a deployed bundle, keep credential files out of source control in a For a deployed bundle, keep credential files out of source control in a
`secrets/` directory beside the root `pipeline.yml`, one file per referenced `secrets/` directory beside the root `pipeline.yml`, one file per referenced

View File

@@ -90,22 +90,18 @@ seriatim:
filler_max_duration: 1.25 filler_max_duration: 1.25
audita: audita:
# Optional overrides; defaults shown explicitly where applicable. # Optional overrides. Audita owns its own configuration and profiles.
binary: audita binary: audita
timeout: 3h timeout: 3h
llm_api_key: AUDITA_LLM_API_KEY # Names must match credentials on every backend in the Audita v2 config.
modules: [glossary, homophones, spoken_word, grammar] credentials: [AUDITA_LLM_API_KEY]
base_url: "" # Omit modules for Audita's default sequence; modules: [] disables corrections.
model: "" overlay: ""
total_llm_concurrency: 2 proposal_profile: ""
proposal_llm_concurrency: 1 validation_profile: ""
validation_model: ""
validation_llm_concurrency: 1
transcript_description: "" transcript_description: ""
config_path: /usr/local/etc/audita/config.yml config_path: /usr/local/etc/audita/config.yml
output_schema: audita-v1 output_schema: audita-v1
work_dir_retention: auto
report: true
normalize: normalize:
# Optional; defaults shown explicitly. # Optional; defaults shown explicitly.
@@ -131,11 +127,11 @@ notarius:
# Optional structured extraction after render and before analyze. # Optional structured extraction after render and before analyze.
enabled: true enabled: true
binary: notarius binary: notarius
# Optional environment-variable reference. Match this name to api_key_env in # Optional environment-variable references. Match these names to the
# the selected Notarius/PromptKit profile; never put the credential here. # selected Notarius/PromptKit providers; never put credential values here.
llm_api_key: NOTARIUS_LLM_API_KEY credentials: [NOTARIUS_LLM_API_KEY]
# Optionally select a Notarius ConfigKit overlay when extraction runs. This # Optionally select a Notarius ConfigKit overlay when extraction runs. This
# is independent of Narratio's selected profile and may use a different name. # is independent of Narratio's selected overlay and may use a different name.
# See docs/config.md and docs/integrations/notarius.md for the contracts. # See docs/config.md and docs/integrations/notarius.md for the contracts.
# config_profile: downstream-economy # config_profile: downstream-economy
config_path: /usr/local/etc/notarius/config.yml config_path: /usr/local/etc/notarius/config.yml

View File

@@ -57,14 +57,9 @@ seriatim:
audita: audita:
binary: audita binary: audita
timeout: 3h timeout: 3h
llm_api_key: AUDITA_LLM_API_KEY credentials: [AUDITA_LLM_API_KEY]
modules: [glossary, homophones, spoken_word, grammar] # Omit modules to use Audita defaults; modules: [] disables corrections.
output_schema: audita-v1 output_schema: audita-v1
work_dir_retention: auto
total_llm_concurrency: 2
proposal_llm_concurrency: 1
validation_llm_concurrency: 1
report: true
normalize: normalize:
output_path: transcripts/final.json output_path: transcripts/final.json

View File

@@ -10,8 +10,8 @@ audita:
binary: audita binary: audita
modules: [glossary, grammar] modules: [glossary, grammar]
output_schema: audita-v1 output_schema: audita-v1
model: narratio-production-model-placeholder proposal_profile: narratio-production-model-placeholder
validation_model: narratio-production-validator-placeholder validation_profile: narratio-production-validator-placeholder
normalize: normalize:
output_path: transcripts/final.json output_path: transcripts/final.json

View File

@@ -1,6 +1,6 @@
audita: audita:
model: narratio-testing-model-placeholder proposal_profile: narratio-testing-model-placeholder
validation_model: narratio-testing-validator-placeholder validation_profile: narratio-testing-validator-placeholder
scriptorium: scriptorium:
artifacts: artifacts:

2
go.mod
View File

@@ -3,7 +3,7 @@ module gitea.maximumdirect.net/eric/narratio
go 1.26.0 go 1.26.0
require ( require (
gitea.maximumdirect.net/eric/ConfigKit v0.3.1 gitea.maximumdirect.net/eric/ConfigKit v0.4.0
github.com/aws/aws-sdk-go-v2/config v1.32.17 github.com/aws/aws-sdk-go-v2/config v1.32.17
github.com/aws/aws-sdk-go-v2/credentials v1.19.16 github.com/aws/aws-sdk-go-v2/credentials v1.19.16
github.com/aws/aws-sdk-go-v2/service/s3 v1.101.0 github.com/aws/aws-sdk-go-v2/service/s3 v1.101.0

4
go.sum
View File

@@ -1,5 +1,5 @@
gitea.maximumdirect.net/eric/ConfigKit v0.3.1 h1:etfTI/dxO3NnS18La0V6IeUh/Iv+3PjVfEyaN8hTuOM= gitea.maximumdirect.net/eric/ConfigKit v0.4.0 h1:fo+vKff3zTGeWqJIA38NtT84b6OUP//9ZmBH3lFuKgk=
gitea.maximumdirect.net/eric/ConfigKit v0.3.1/go.mod h1:tYWpsrbLyu05r8+1MapWp5fN6ZrX9I8hU2xEPedYmYk= gitea.maximumdirect.net/eric/ConfigKit v0.4.0/go.mod h1:tYWpsrbLyu05r8+1MapWp5fN6ZrX9I8hU2xEPedYmYk=
github.com/aws/aws-sdk-go-v2 v1.41.7 h1:DWpAJt66FmnnaRIOT/8ASTucrvuDPZASqhhLey6tLY8= github.com/aws/aws-sdk-go-v2 v1.41.7 h1:DWpAJt66FmnnaRIOT/8ASTucrvuDPZASqhhLey6tLY8=
github.com/aws/aws-sdk-go-v2 v1.41.7/go.mod h1:4LAfZOPHNVNQEckOACQx60Y8pSRjIkNZQz1w92xpMJc= github.com/aws/aws-sdk-go-v2 v1.41.7/go.mod h1:4LAfZOPHNVNQEckOACQx60Y8pSRjIkNZQz1w92xpMJc=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.10 h1:gx1AwW1Iyk9Z9dD9F4akX5gnN3QZwUB20GGKH/I+Rho= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.10 h1:gx1AwW1Iyk9Z9dD9F4akX5gnN3QZwUB20GGKH/I+Rho=

View File

@@ -17,13 +17,11 @@ func (n *NoopRunner) Run(ctx context.Context, req PolishRequest) (PolishResult,
if err := ctx.Err(); err != nil { if err := ctx.Err(); err != nil {
return PolishResult{}, err return PolishResult{}, err
} }
if err := materializePlaceholders(req); err != nil { if err := materializePlaceholders(req, false); err != nil {
return PolishResult{}, err return PolishResult{}, err
} }
return PolishResult{ return PolishResult{
ProcessedTranscriptPath: req.OutputProcessedPath, ProcessedTranscriptPath: req.OutputProcessedPath,
ReportPath: req.ReportPath,
WorkDir: req.WorkDir,
StdoutLogPath: req.StdoutLogPath, StdoutLogPath: req.StdoutLogPath,
StderrLogPath: req.StderrLogPath, StderrLogPath: req.StderrLogPath,
GeneratedConfigPath: req.GeneratedConfigPath, GeneratedConfigPath: req.GeneratedConfigPath,
@@ -47,18 +45,20 @@ func (f *FakeRunner) Run(ctx context.Context, req PolishRequest) (PolishResult,
if f.Err != nil { if f.Err != nil {
return PolishResult{}, f.Err return PolishResult{}, f.Err
} }
if err := materializePlaceholders(req); err != nil { if err := materializePlaceholders(req, true); err != nil {
return PolishResult{}, err return PolishResult{}, err
} }
res := f.Result res := f.Result
if res.ProcessedTranscriptPath == "" { if res.ProcessedTranscriptPath == "" {
res.ProcessedTranscriptPath = req.OutputProcessedPath res.ProcessedTranscriptPath = req.OutputProcessedPath
} }
if res.ReportPath == "" { if res.Reports == (ReportBundle{}) {
res.ReportPath = req.ReportPath dir := filepath.Dir(req.OutputProcessedPath)
} res.Reports = ReportBundle{
if res.WorkDir == "" { ErrorsPath: filepath.Join(dir, "errors.yml"),
res.WorkDir = req.WorkDir RecoveriesPath: filepath.Join(dir, "recoveries.yml"),
OverviewPath: filepath.Join(dir, "report.md"),
}
} }
if res.StdoutLogPath == "" { if res.StdoutLogPath == "" {
res.StdoutLogPath = req.StdoutLogPath res.StdoutLogPath = req.StdoutLogPath
@@ -75,10 +75,10 @@ func (f *FakeRunner) Run(ctx context.Context, req PolishRequest) (PolishResult,
return res, nil return res, nil
} }
func materializePlaceholders(req PolishRequest) error { func materializePlaceholders(req PolishRequest, reports bool) error {
if req.GeneratedConfigPath != "" { if req.GeneratedConfigPath != "" {
payload := map[string]any{ payload := map[string]any{
"schema": "audita.generated.v1", "schema": "audita.generated.v2",
"placeholder": true, "placeholder": true,
"merged_transcript_path": req.MergedTranscriptPath, "merged_transcript_path": req.MergedTranscriptPath,
"output_path": req.OutputProcessedPath, "output_path": req.OutputProcessedPath,
@@ -103,11 +103,18 @@ func materializePlaceholders(req PolishRequest) error {
}); err != nil { }); err != nil {
return err return err
} }
if err := writeJSONIfRequested(req.ReportPath, map[string]any{ if !reports {
"schema": "audita.report.v1", return nil
"steps": []any{}, }
}); err != nil { for _, report := range []struct{ name, contents string }{
return err {"errors.yml", "schema: audita-errors\nversion: 1\nstatus: completed\nerrors: []\n"},
{"recoveries.yml", "schema: audita-recoveries\nversion: 1\nstatus: completed\nrecoveries: []\n"},
{"report.md", "# Audita report\n"},
} {
path := filepath.Join(filepath.Dir(req.OutputProcessedPath), report.name)
if err := fileops.WriteFileAtomic(path, []byte(report.contents), fileops.WorkspaceFileMode); err != nil {
return fmt.Errorf("write report %q: %w", path, err)
}
} }
return nil return nil
} }

View File

@@ -11,24 +11,29 @@ type Runner interface {
Run(ctx context.Context, req PolishRequest) (PolishResult, error) Run(ctx context.Context, req PolishRequest) (PolishResult, error)
} }
// PolishRequest describes an audita invocation. // PolishRequest describes an Audita invocation. Nil Modules uses the runner's
// configured selection; a non-nil empty slice selects no modules.
type PolishRequest struct { type PolishRequest struct {
GeneratedConfigPath string GeneratedConfigPath string
MergedTranscriptPath string MergedTranscriptPath string
OutputProcessedPath string OutputProcessedPath string
GlossaryPath string GlossaryPath string
ReportPath string
WorkDir string
Modules []string Modules []string
StdoutLogPath string StdoutLogPath string
StderrLogPath string StderrLogPath string
} }
// PolishResult describes a polish output. // ReportBundle contains optional reports adjacent to the requested output.
type ReportBundle struct {
ErrorsPath string
RecoveriesPath string
OverviewPath string
}
// PolishResult describes a polish output and available diagnostics.
type PolishResult struct { type PolishResult struct {
ProcessedTranscriptPath string ProcessedTranscriptPath string
ReportPath string Reports ReportBundle
WorkDir string
StdoutLogPath string StdoutLogPath string
StderrLogPath string StderrLogPath string
GeneratedConfigPath string GeneratedConfigPath string

View File

@@ -3,12 +3,14 @@ package audita
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"net/url" "os"
"strconv" "path/filepath"
"strings" "strings"
"time" "time"
configkit "gitea.maximumdirect.net/eric/ConfigKit"
"gitea.maximumdirect.net/eric/narratio/internal/adapters/subprocess" "gitea.maximumdirect.net/eric/narratio/internal/adapters/subprocess"
"gitea.maximumdirect.net/eric/narratio/internal/fileops" "gitea.maximumdirect.net/eric/narratio/internal/fileops"
) )
@@ -16,93 +18,27 @@ import (
// MaxProcessedOutputBytes bounds Audita's processed-transcript JSON result. // MaxProcessedOutputBytes bounds Audita's processed-transcript JSON result.
const MaxProcessedOutputBytes int64 = 64 * 1024 * 1024 const MaxProcessedOutputBytes int64 = 64 * 1024 * 1024
// MaxReportOutputBytes bounds Audita's optional report JSON result. // MaxReportOutputBytes bounds each optional Audita report.
const MaxReportOutputBytes int64 = 16 * 1024 * 1024 const MaxReportOutputBytes int64 = 16 * 1024 * 1024
// SubprocessRunnerConfig defines deterministic settings for Audita CLI execution. // SubprocessRunnerConfig defines deterministic settings for Audita CLI execution.
type SubprocessRunnerConfig struct { type SubprocessRunnerConfig struct {
Binary string Binary string
Timeout time.Duration Timeout time.Duration
LLMAPIKey string Credentials []configkit.Secret
LLMAPIKeyReference string Modules []string
Modules []string Overlay string
BaseURL string ProposalProfile string
Model string ValidationProfile string
TranscriptDescription string TranscriptDescription string
ConfigPath string ConfigPath string
OutputSchema string OutputSchema string
WorkDirRetention string
TotalLLMConcurrency *int
ProposalLLMConcurrency *int
ValidationModel string
ValidationLLMConcurrency *int
Report bool
} }
// SubprocessRunner invokes Audita via subprocess. // SubprocessRunner invokes Audita via subprocess.
type SubprocessRunner struct { type SubprocessRunner struct {
binary string cfg SubprocessRunnerConfig
timeout time.Duration run func(context.Context, subprocess.RunRequest) (subprocess.RunResult, error)
llmAPIKey string
llmAPIKeyReference string
modules []string
baseURL string
model string
transcriptDescription string
configPath string
outputSchema string
workDirRetention string
totalLLMConcurrency *int
proposalLLMConcurrency *int
validationModel string
validationLLMConcurrency *int
report bool
}
// NewSubprocessRunnerFromConfigValues parses config-derived values once.
func NewSubprocessRunnerFromConfigValues(
binary string,
timeout string,
llmAPIKey string,
llmAPIKeyReference string,
modules []string,
baseURL string,
model string,
transcriptDescription string,
configPath string,
outputSchema string,
workDirRetention string,
totalLLMConcurrency *int,
proposalLLMConcurrency *int,
validationModel string,
validationLLMConcurrency *int,
report bool,
) (*SubprocessRunner, error) {
if strings.TrimSpace(timeout) == "" {
return nil, fmt.Errorf("audita timeout is required")
}
parsedTimeout, err := time.ParseDuration(timeout)
if err != nil {
return nil, fmt.Errorf("parse audita timeout %q: %w", timeout, err)
}
return NewSubprocessRunner(SubprocessRunnerConfig{
Binary: binary,
Timeout: parsedTimeout,
LLMAPIKey: llmAPIKey,
LLMAPIKeyReference: llmAPIKeyReference,
Modules: modules,
BaseURL: baseURL,
Model: model,
TranscriptDescription: transcriptDescription,
ConfigPath: configPath,
OutputSchema: outputSchema,
WorkDirRetention: workDirRetention,
TotalLLMConcurrency: totalLLMConcurrency,
ProposalLLMConcurrency: proposalLLMConcurrency,
ValidationModel: validationModel,
ValidationLLMConcurrency: validationLLMConcurrency,
Report: report,
})
} }
// NewSubprocessRunner constructs a validated Audita subprocess runner. // NewSubprocessRunner constructs a validated Audita subprocess runner.
@@ -113,281 +49,177 @@ func NewSubprocessRunner(cfg SubprocessRunnerConfig) (*SubprocessRunner, error)
if cfg.Timeout <= 0 { if cfg.Timeout <= 0 {
return nil, fmt.Errorf("audita timeout must be > 0") return nil, fmt.Errorf("audita timeout must be > 0")
} }
if (cfg.LLMAPIKey == "") != (strings.TrimSpace(cfg.LLMAPIKeyReference) == "") {
return nil, fmt.Errorf("audita credential value and reference must be provided together")
}
for i, module := range cfg.Modules { for i, module := range cfg.Modules {
if strings.TrimSpace(module) == "" { if strings.TrimSpace(module) == "" {
return nil, fmt.Errorf("audita module at index %d is empty", i) return nil, fmt.Errorf("audita module at index %d is empty", i)
} }
} }
if strings.TrimSpace(cfg.BaseURL) != "" {
u, err := url.Parse(cfg.BaseURL)
if err != nil || u.Scheme == "" || u.Host == "" {
if err != nil {
return nil, fmt.Errorf("audita base url %q is invalid: %w", cfg.BaseURL, err)
}
return nil, fmt.Errorf("audita base url %q is invalid", cfg.BaseURL)
}
}
if cfg.TotalLLMConcurrency != nil && *cfg.TotalLLMConcurrency <= 0 {
return nil, fmt.Errorf("audita total llm concurrency must be > 0 when provided")
}
if cfg.ProposalLLMConcurrency != nil && *cfg.ProposalLLMConcurrency <= 0 {
return nil, fmt.Errorf("audita proposal llm concurrency must be > 0 when provided")
}
if cfg.ValidationLLMConcurrency != nil && *cfg.ValidationLLMConcurrency <= 0 {
return nil, fmt.Errorf("audita validation llm concurrency must be > 0 when provided")
}
switch strings.TrimSpace(cfg.OutputSchema) { switch strings.TrimSpace(cfg.OutputSchema) {
case "", "bare-segments", "audita-v1": case "", "bare-segments", "audita-v1":
default: default:
return nil, fmt.Errorf("audita output schema must be one of: bare-segments, audita-v1") return nil, fmt.Errorf("audita output schema must be one of: bare-segments, audita-v1")
} }
switch strings.TrimSpace(cfg.WorkDirRetention) { cfg.Binary = strings.TrimSpace(cfg.Binary)
case "", "always", "auto", "never": cfg.Credentials = append([]configkit.Secret(nil), cfg.Credentials...)
default: cfg.Modules = cloneModules(cfg.Modules)
return nil, fmt.Errorf("audita work dir retention must be one of: always, auto, never") for i := range cfg.Modules {
cfg.Modules[i] = strings.TrimSpace(cfg.Modules[i])
} }
return &SubprocessRunner{cfg: cfg, run: subprocess.Run}, nil
modules := make([]string, len(cfg.Modules))
for i, m := range cfg.Modules {
modules[i] = strings.TrimSpace(m)
}
return &SubprocessRunner{
binary: strings.TrimSpace(cfg.Binary),
timeout: cfg.Timeout,
llmAPIKey: cfg.LLMAPIKey,
llmAPIKeyReference: strings.TrimSpace(cfg.LLMAPIKeyReference),
modules: modules,
baseURL: strings.TrimSpace(cfg.BaseURL),
model: strings.TrimSpace(cfg.Model),
transcriptDescription: strings.TrimSpace(cfg.TranscriptDescription),
configPath: strings.TrimSpace(cfg.ConfigPath),
outputSchema: strings.TrimSpace(cfg.OutputSchema),
workDirRetention: strings.TrimSpace(cfg.WorkDirRetention),
totalLLMConcurrency: cfg.TotalLLMConcurrency,
proposalLLMConcurrency: cfg.ProposalLLMConcurrency,
validationModel: strings.TrimSpace(cfg.ValidationModel),
validationLLMConcurrency: cfg.ValidationLLMConcurrency,
report: cfg.Report,
}, nil
} }
// Run executes Audita process with deterministic flags and validates output artifacts. func cloneModules(modules []string) []string {
if modules == nil {
return nil
}
return append([]string{}, modules...)
}
// Run executes Audita process and validates its corrected transcript.
func (r *SubprocessRunner) Run(ctx context.Context, req PolishRequest) (PolishResult, error) { func (r *SubprocessRunner) Run(ctx context.Context, req PolishRequest) (PolishResult, error) {
if r == nil { if r == nil {
return PolishResult{}, fmt.Errorf("audita subprocess runner is nil") return PolishResult{}, fmt.Errorf("audita subprocess runner is nil")
} }
if strings.TrimSpace(req.MergedTranscriptPath) == "" { for _, field := range []struct{ name, value string }{
return PolishResult{}, fmt.Errorf("audita merged transcript path is required") {"merged transcript path", req.MergedTranscriptPath},
{"glossary path", req.GlossaryPath},
{"output processed path", req.OutputProcessedPath},
} {
if strings.TrimSpace(field.value) == "" {
return PolishResult{}, fmt.Errorf("audita %s is required", field.name)
}
} }
if strings.TrimSpace(req.GlossaryPath) == "" { modules := req.Modules
return PolishResult{}, fmt.Errorf("audita glossary path is required") if modules == nil {
modules = r.cfg.Modules
} }
if strings.TrimSpace(req.OutputProcessedPath) == "" { for i, module := range modules {
return PolishResult{}, fmt.Errorf("audita output processed path is required") if strings.TrimSpace(module) == "" {
return PolishResult{}, fmt.Errorf("audita module at index %d is empty", i)
}
} }
if strings.TrimSpace(req.WorkDir) == "" { modules = cloneModules(modules)
return PolishResult{}, fmt.Errorf("audita work dir is required") for i := range modules {
modules[i] = strings.TrimSpace(modules[i])
} }
if r.report && strings.TrimSpace(req.ReportPath) == "" { args := r.buildArgs(req, modules)
return PolishResult{}, fmt.Errorf("audita report is enabled but report path is missing") env, names, err := subprocess.CredentialEnvironment(r.cfg.Credentials)
if err != nil {
return PolishResult{}, fmt.Errorf("audita credentials: %w", err)
} }
reqModules := req.Modules
if reqModules == nil {
reqModules = append([]string(nil), r.modules...)
}
args := r.buildArgs(req, reqModules)
credentialPresent := r.llmAPIKeyReference != ""
env := map[string]string{}
if credentialPresent {
env["AUDITA_LLM_API_KEY"] = r.llmAPIKey
}
if req.GeneratedConfigPath != "" { if req.GeneratedConfigPath != "" {
if err := r.writeInvocationConfig(req, args, reqModules, credentialPresent); err != nil { if err := r.writeInvocationConfig(req, args, modules, names); err != nil {
return PolishResult{}, fmt.Errorf("write audita invocation config %q: %w", req.GeneratedConfigPath, err) return PolishResult{}, fmt.Errorf("write audita invocation config %q: %w", req.GeneratedConfigPath, err)
} }
} }
run := r.run
runRes, err := subprocess.Run(ctx, subprocess.RunRequest{ if run == nil {
Executable: r.binary, run = subprocess.Run
Args: args, }
Timeout: r.timeout, runRes, runErr := run(ctx, subprocess.RunRequest{
EnvOverrides: env, Executable: r.cfg.Binary, Args: args, Timeout: r.cfg.Timeout,
DiagnosticOwner: "audita", EnvOverrides: env, SensitiveEnvNames: names, DiagnosticOwner: "audita",
StdoutLogPath: req.StdoutLogPath, StdoutLogPath: req.StdoutLogPath, StderrLogPath: req.StderrLogPath,
StderrLogPath: req.StderrLogPath,
}) })
if err != nil { result := r.result(req, modules, names, runRes)
wrappedMessage := fmt.Sprintf( if runErr != nil {
"run audita process (binary=%q, stdout_log=%q, stderr_log=%q)", result.Reports, _ = discoverReports(req.OutputProcessedPath)
r.binary, return result, fmt.Errorf("run audita process (binary=%q, output_dir=%q, stdout_log=%q, stderr_log=%q): %w",
req.StdoutLogPath, r.cfg.Binary, filepath.Dir(req.OutputProcessedPath), req.StdoutLogPath, req.StderrLogPath, runErr)
req.StderrLogPath,
)
wrappedMessage = addSubprocessStreamHint(wrappedMessage, err)
return r.failureResult(req, reqModules, runRes, credentialPresent), fmt.Errorf(
"%s: %w",
wrappedMessage,
err,
)
} }
if err := validateProcessedOutput(req.OutputProcessedPath); err != nil { if err := validateProcessedOutput(req.OutputProcessedPath); err != nil {
return r.failureResult(req, reqModules, runRes, credentialPresent), fmt.Errorf("validate audita processed output %q: %w", req.OutputProcessedPath, err) result.Reports, _ = discoverReports(req.OutputProcessedPath)
return result, fmt.Errorf("validate audita processed output %q: %w", req.OutputProcessedPath, err)
} }
if r.report { reports, err := discoverReports(req.OutputProcessedPath)
if err := validateJSONFile(req.ReportPath); err != nil { if err != nil {
return r.failureResult(req, reqModules, runRes, credentialPresent), fmt.Errorf("validate audita report output %q: %w", req.ReportPath, err) return result, err
}
} }
result.Reports = reports
return PolishResult{ return result, nil
ProcessedTranscriptPath: req.OutputProcessedPath,
ReportPath: req.ReportPath,
WorkDir: req.WorkDir,
StdoutLogPath: req.StdoutLogPath,
StderrLogPath: req.StderrLogPath,
GeneratedConfigPath: req.GeneratedConfigPath,
ExitCode: runRes.ExitCode,
Duration: runRes.Duration,
InvokedBinary: r.binary,
Metadata: map[string]any{
"adapter": "audita_subprocess",
"modules": reqModules,
"base_url": r.baseURL,
"model": r.model,
"transcript_description": r.transcriptDescription,
"config_path": r.configPath,
"output_schema": r.outputSchema,
"work_dir_retention": r.workDirRetention,
"validation_model": r.validationModel,
"total_llm_concurrency": r.totalLLMConcurrency,
"proposal_llm_concurrency": r.proposalLLMConcurrency,
"validation_llm_concurrency": r.validationLLMConcurrency,
"credential_env_var": r.llmAPIKeyReference,
"credential_present": credentialPresent,
},
}, nil
} }
func (r *SubprocessRunner) failureResult(req PolishRequest, modules []string, runRes subprocess.RunResult, credentialPresent bool) PolishResult { func (r *SubprocessRunner) result(req PolishRequest, modules, names []string, runRes subprocess.RunResult) PolishResult {
return PolishResult{ return PolishResult{
ProcessedTranscriptPath: req.OutputProcessedPath, ProcessedTranscriptPath: req.OutputProcessedPath,
ReportPath: req.ReportPath, StdoutLogPath: req.StdoutLogPath, StderrLogPath: req.StderrLogPath,
WorkDir: req.WorkDir, GeneratedConfigPath: req.GeneratedConfigPath, ExitCode: runRes.ExitCode,
StdoutLogPath: req.StdoutLogPath, Duration: runRes.Duration, InvokedBinary: r.cfg.Binary,
StderrLogPath: req.StderrLogPath,
GeneratedConfigPath: req.GeneratedConfigPath,
ExitCode: runRes.ExitCode,
Duration: runRes.Duration,
InvokedBinary: r.binary,
Metadata: map[string]any{ Metadata: map[string]any{
"adapter": "audita_subprocess", "adapter": "audita_subprocess", "modules": modules,
"modules": modules, "overlay": r.cfg.Overlay, "proposal_profile": r.cfg.ProposalProfile,
"base_url": r.baseURL, "validation_profile": r.cfg.ValidationProfile,
"model": r.model, "transcript_description": r.cfg.TranscriptDescription,
"transcript_description": r.transcriptDescription, "config_path": r.cfg.ConfigPath, "output_schema": r.cfg.OutputSchema,
"config_path": r.configPath, "credential_names": names,
"output_schema": r.outputSchema,
"work_dir_retention": r.workDirRetention,
"validation_model": r.validationModel,
"total_llm_concurrency": r.totalLLMConcurrency,
"proposal_llm_concurrency": r.proposalLLMConcurrency,
"validation_llm_concurrency": r.validationLLMConcurrency,
"credential_env_var": r.llmAPIKeyReference,
"credential_present": credentialPresent,
}, },
} }
} }
func (r *SubprocessRunner) buildArgs(req PolishRequest, modules []string) []string { func (r *SubprocessRunner) buildArgs(req PolishRequest, modules []string) []string {
args := []string{ args := []string{"process", req.MergedTranscriptPath, "--glossary", req.GlossaryPath, "--output", req.OutputProcessedPath}
"process", if modules != nil {
req.MergedTranscriptPath,
"--glossary", req.GlossaryPath,
"--output", req.OutputProcessedPath,
"--work-dir", req.WorkDir,
}
if r.baseURL != "" {
args = append(args, "--base-url", r.baseURL)
}
if r.model != "" {
args = append(args, "--model", r.model)
}
if len(modules) > 0 {
args = append(args, "--modules", strings.Join(modules, ",")) args = append(args, "--modules", strings.Join(modules, ","))
} }
if r.report { for _, setting := range []struct{ flag, value string }{
args = append(args, "--report-json", req.ReportPath) {"--config", r.cfg.ConfigPath}, {"--overlay", r.cfg.Overlay},
} {"--proposal-profile", r.cfg.ProposalProfile}, {"--validation-profile", r.cfg.ValidationProfile},
if r.transcriptDescription != "" { {"--transcript-description", r.cfg.TranscriptDescription}, {"--output-schema", r.cfg.OutputSchema},
args = append(args, "--transcript-description", r.transcriptDescription) } {
} if setting.value != "" {
if r.configPath != "" { args = append(args, setting.flag, setting.value)
args = append(args, "--config", r.configPath) }
}
if r.outputSchema != "" {
args = append(args, "--output-schema", r.outputSchema)
}
if r.workDirRetention != "" {
args = append(args, "--work-dir-retention", r.workDirRetention)
}
if r.totalLLMConcurrency != nil {
args = append(args, "--total-llm-concurrency", strconv.Itoa(*r.totalLLMConcurrency))
}
if r.proposalLLMConcurrency != nil {
args = append(args, "--proposal-llm-concurrency", strconv.Itoa(*r.proposalLLMConcurrency))
}
if r.validationModel != "" {
args = append(args, "--validation-model", r.validationModel)
}
if r.validationLLMConcurrency != nil {
args = append(args, "--validation-llm-concurrency", strconv.Itoa(*r.validationLLMConcurrency))
} }
return args return args
} }
func (r *SubprocessRunner) writeInvocationConfig(req PolishRequest, args []string, modules []string, credentialPresent bool) error { func (r *SubprocessRunner) writeInvocationConfig(req PolishRequest, args, modules, names []string) error {
payload := map[string]any{ return writeGeneratedYAML(req.GeneratedConfigPath, map[string]any{
"schema": "audita.generated.v1", "schema": "audita.generated.v2", "binary": r.cfg.Binary, "args": args,
"binary": r.binary, "timeout": r.cfg.Timeout.String(), "modules": modules,
"args": args, "overlay": r.cfg.Overlay, "proposal_profile": r.cfg.ProposalProfile,
"timeout": r.timeout.String(), "validation_profile": r.cfg.ValidationProfile,
"modules": modules, "transcript_description": r.cfg.TranscriptDescription,
"base_url": r.baseURL, "config_path": r.cfg.ConfigPath, "output_schema": r.cfg.OutputSchema,
"model": r.model, "merged_transcript_path": req.MergedTranscriptPath, "glossary_path": req.GlossaryPath,
"transcript_description": r.transcriptDescription, "output_path": req.OutputProcessedPath, "credential_names": names,
"config_path": r.configPath, })
"output_schema": r.outputSchema, }
"work_dir_retention": r.workDirRetention,
"validation_model": r.validationModel, func discoverReports(outputPath string) (ReportBundle, error) {
"total_llm_concurrency": r.totalLLMConcurrency, var reports ReportBundle
"proposal_llm_concurrency": r.proposalLLMConcurrency, for _, report := range []struct {
"validation_llm_concurrency": r.validationLLMConcurrency, name string
"report_enabled": r.report, dest *string
"merged_transcript_path": req.MergedTranscriptPath, }{
"glossary_path": req.GlossaryPath, {"errors.yml", &reports.ErrorsPath},
"output_path": req.OutputProcessedPath, {"recoveries.yml", &reports.RecoveriesPath},
"report_path": req.ReportPath, {"report.md", &reports.OverviewPath},
"work_dir": req.WorkDir, } {
"credential_env_var": r.llmAPIKeyReference, path := filepath.Join(filepath.Dir(outputPath), report.name)
"credential_present": credentialPresent, info, err := os.Lstat(path)
if errors.Is(err, os.ErrNotExist) {
continue
}
if err != nil {
return reports, fmt.Errorf("inspect audita report %q: %w", path, err)
}
if !info.Mode().IsRegular() {
return reports, fmt.Errorf("audita report %q is not a regular file", path)
}
if _, err := fileops.ReadFileBounded(path, MaxReportOutputBytes); err != nil {
return reports, fmt.Errorf("audita report %q exceeds or cannot be read within %d-byte limit: %w", path, MaxReportOutputBytes, err)
}
*report.dest = path
} }
return writeGeneratedYAML(req.GeneratedConfigPath, payload) return reports, nil
} }
func validateProcessedOutput(path string) error { func validateProcessedOutput(path string) error {
data, err := readAuditaResult(path, MaxProcessedOutputBytes, "processed transcript") data, err := fileops.ReadFileBounded(path, MaxProcessedOutputBytes)
if err != nil { if err != nil {
return err return fmt.Errorf("audita processed transcript result exceeds or cannot be read within %d-byte limit: %w", MaxProcessedOutputBytes, err)
} }
var payload map[string]any var payload map[string]any
if err := json.Unmarshal(data, &payload); err != nil { if err := json.Unmarshal(data, &payload); err != nil {
return fmt.Errorf("parse json: %w", err) return fmt.Errorf("parse json: %w", err)
@@ -401,34 +233,3 @@ func validateProcessedOutput(path string) error {
} }
return nil return nil
} }
func addSubprocessStreamHint(message string, runErr error) string {
if runErr == nil {
return message
}
lower := strings.ToLower(runErr.Error())
if strings.Contains(lower, "bad file descriptor") || strings.Contains(lower, "exit code 120") {
return message + "; hint=audita child process may have started with invalid stderr/stdout descriptors"
}
return message
}
func validateJSONFile(path string) error {
data, err := readAuditaResult(path, MaxReportOutputBytes, "report")
if err != nil {
return err
}
var v any
if err := json.Unmarshal(data, &v); err != nil {
return fmt.Errorf("parse json: %w", err)
}
return nil
}
func readAuditaResult(path string, limit int64, category string) ([]byte, error) {
data, err := fileops.ReadFileBounded(path, limit)
if err != nil {
return nil, fmt.Errorf("audita %s result exceeds or cannot be read within %d-byte limit: %w", category, limit, err)
}
return data, nil
}

View File

@@ -2,630 +2,262 @@ package audita
import ( import (
"context" "context"
"encoding/json" "errors"
"fmt"
"os" "os"
"path/filepath" "path/filepath"
"reflect"
"strings" "strings"
"testing" "testing"
"time" "time"
configkit "gitea.maximumdirect.net/eric/ConfigKit"
"gitea.maximumdirect.net/eric/narratio/internal/adapters/subprocess"
) )
func TestSubprocessRunnerSuccessArgsEnvAndValidation(t *testing.T) { func auditaTestRequest(t *testing.T) PolishRequest {
t.Helper()
t.Setenv("GO_WANT_AUDITA_HELPER", "1")
t.Setenv("AUDITA_HELPER_MODE", "success")
t.Setenv("OPENAI_KEY_SOURCE", "super-secret")
recordPath := filepath.Join(t.TempDir(), "record.json")
t.Setenv("AUDITA_HELPER_RECORD_PATH", recordPath)
wrapper := writeAuditaHelperWrapper(t)
totalLLMConcurrency := 3
proposalLLMConcurrency := 2
validationLLMConcurrency := 2
runner, err := NewSubprocessRunner(SubprocessRunnerConfig{
Binary: wrapper,
Timeout: mustParseAuditaDuration(t, "2s"),
LLMAPIKey: "super-secret",
LLMAPIKeyReference: "OPENAI_KEY_SOURCE",
Modules: []string{"glossary", "homophones", "glossary"},
BaseURL: "https://openrouter.ai/api/v1",
Model: "openrouter/google/gemma-4-31b-it",
TranscriptDescription: "Campaign Session 42",
ConfigPath: "/etc/audita/config.yml",
OutputSchema: "audita-v1",
WorkDirRetention: "auto",
TotalLLMConcurrency: &totalLLMConcurrency,
ProposalLLMConcurrency: &proposalLLMConcurrency,
ValidationModel: "openrouter/google/gemma-4-31b-it",
ValidationLLMConcurrency: &validationLLMConcurrency,
Report: true,
})
if err != nil {
t.Fatalf("NewSubprocessRunner() error = %v", err)
}
t.Setenv("OPENAI_KEY_SOURCE", "changed-after-resolution")
dir := t.TempDir() dir := t.TempDir()
req := PolishRequest{ return PolishRequest{
GeneratedConfigPath: filepath.Join(dir, "audita.generated.yml"), MergedTranscriptPath: filepath.Join(dir, "merged.json"),
MergedTranscriptPath: filepath.Join(dir, "base.json"),
GlossaryPath: filepath.Join(dir, "glossary.yml"), GlossaryPath: filepath.Join(dir, "glossary.yml"),
OutputProcessedPath: filepath.Join(dir, "polished.json"), OutputProcessedPath: filepath.Join(dir, "polished.json"),
ReportPath: filepath.Join(dir, "audita.report.json"),
WorkDir: filepath.Join(dir, "artifacts", "audita-work"),
StdoutLogPath: filepath.Join(dir, "audita.stdout.log"),
StderrLogPath: filepath.Join(dir, "audita.stderr.log"),
}
writeAuditaTestFile(t, req.MergedTranscriptPath, `{"segments":[]}`)
writeAuditaTestFile(t, req.GlossaryPath, "terms: []\n")
res, err := runner.Run(context.Background(), req)
if err != nil {
t.Fatalf("Run() error = %v", err)
}
if res.ProcessedTranscriptPath != req.OutputProcessedPath {
t.Fatalf("ProcessedTranscriptPath = %q, want %q", res.ProcessedTranscriptPath, req.OutputProcessedPath)
}
if res.ReportPath != req.ReportPath {
t.Fatalf("ReportPath = %q, want %q", res.ReportPath, req.ReportPath)
}
if res.WorkDir != req.WorkDir {
t.Fatalf("WorkDir = %q, want %q", res.WorkDir, req.WorkDir)
}
if res.InvokedBinary != wrapper {
t.Fatalf("InvokedBinary = %q, want %q", res.InvokedBinary, wrapper)
}
if res.ExitCode != 0 {
t.Fatalf("ExitCode = %d, want 0", res.ExitCode)
}
if res.Duration <= 0 {
t.Fatalf("Duration = %s, want > 0", res.Duration)
}
assertJSONFileAudita(t, req.OutputProcessedPath)
assertJSONFileAudita(t, req.ReportPath)
if _, err := os.Stat(req.StdoutLogPath); err != nil {
t.Fatalf("stdout log missing: %v", err)
}
if _, err := os.Stat(req.StderrLogPath); err != nil {
t.Fatalf("stderr log missing: %v", err)
}
rec := readAuditaHelperRecord(t, recordPath)
wantArgs := []string{
"process", req.MergedTranscriptPath,
"--glossary", req.GlossaryPath,
"--output", req.OutputProcessedPath,
"--work-dir", req.WorkDir,
"--base-url", "https://openrouter.ai/api/v1",
"--model", "openrouter/google/gemma-4-31b-it",
"--modules", "glossary,homophones,glossary",
"--report-json", req.ReportPath,
"--transcript-description", "Campaign Session 42",
"--config", "/etc/audita/config.yml",
"--output-schema", "audita-v1",
"--work-dir-retention", "auto",
"--total-llm-concurrency", "3",
"--proposal-llm-concurrency", "2",
"--validation-model", "openrouter/google/gemma-4-31b-it",
"--validation-llm-concurrency", "2",
}
if strings.Join(rec.Args, "\n") != strings.Join(wantArgs, "\n") {
t.Fatalf("args = %#v, want %#v", rec.Args, wantArgs)
}
if rec.Env["AUDITA_LLM_API_KEY"] != "super-secret" {
t.Fatalf("AUDITA_LLM_API_KEY = %q, want propagated secret", rec.Env["AUDITA_LLM_API_KEY"])
}
if rec.Env["AUDITA_LLM_CONCURRENCY"] != "" {
t.Fatalf("AUDITA_LLM_CONCURRENCY = %q, want empty/omitted", rec.Env["AUDITA_LLM_CONCURRENCY"])
}
cfgData, err := os.ReadFile(req.GeneratedConfigPath)
if err != nil {
t.Fatalf("read generated config: %v", err)
}
if strings.Contains(string(cfgData), "super-secret") {
t.Fatalf("generated config must not contain credential value")
}
}
func TestSubprocessRunnerRejectsIncompleteResolvedCredential(t *testing.T) {
_, err := NewSubprocessRunner(SubprocessRunnerConfig{
Binary: writeAuditaHelperWrapper(t),
Timeout: mustParseAuditaDuration(t, "2s"),
LLMAPIKeyReference: "MISSING_AUDITA_KEY",
})
if err == nil || !strings.Contains(err.Error(), "credential value and reference must be provided together") {
t.Fatalf("NewSubprocessRunner() error = %v, want credential pair error", err)
}
}
func TestSubprocessRunnerUnconfiguredCredentialEnvOmitsCredential(t *testing.T) {
t.Setenv("GO_WANT_AUDITA_HELPER", "1")
t.Setenv("AUDITA_HELPER_MODE", "success")
recordPath := filepath.Join(t.TempDir(), "record.json")
t.Setenv("AUDITA_HELPER_RECORD_PATH", recordPath)
runner := mustAuditaRunner(t, SubprocessRunnerConfig{
Binary: writeAuditaHelperWrapper(t),
Timeout: mustParseAuditaDuration(t, "2s"),
LLMAPIKey: "",
Modules: []string{"glossary"},
BaseURL: "https://openrouter.ai/api/v1",
Model: "openrouter/google/gemma-4-31b-it",
Report: false,
})
req := auditaReqForTest(t, false)
res, err := runner.Run(context.Background(), req)
if err != nil {
t.Fatalf("Run() error = %v", err)
}
if res.Metadata["credential_present"] != false {
t.Fatalf("credential_present = %#v, want false", res.Metadata["credential_present"])
}
rec := readAuditaHelperRecord(t, recordPath)
if rec.Env["AUDITA_LLM_API_KEY"] != "" {
t.Fatalf("AUDITA_LLM_API_KEY = %q, want omitted/empty", rec.Env["AUDITA_LLM_API_KEY"])
}
}
func TestSubprocessRunnerOmitsUnspecifiedParentEnvironment(t *testing.T) {
t.Setenv("GO_WANT_AUDITA_HELPER", "1")
t.Setenv("AUDITA_HELPER_MODE", "success")
t.Setenv("AUDITA_INHERITED_MARKER", "inherited-from-parent")
recordPath := filepath.Join(t.TempDir(), "record.json")
t.Setenv("AUDITA_HELPER_RECORD_PATH", recordPath)
runner := mustAuditaRunner(t, SubprocessRunnerConfig{
Binary: writeAuditaHelperWrapper(t),
Timeout: mustParseAuditaDuration(t, "2s"),
Modules: []string{"glossary"},
BaseURL: "https://openrouter.ai/api/v1",
Model: "openrouter/google/gemma-4-31b-it",
Report: false,
LLMAPIKey: "",
})
req := auditaReqForTest(t, false)
if _, err := runner.Run(context.Background(), req); err != nil {
t.Fatalf("Run() error = %v", err)
}
rec := readAuditaHelperRecord(t, recordPath)
if rec.Env["AUDITA_INHERITED_MARKER"] != "" {
t.Fatalf("AUDITA_INHERITED_MARKER = %q, want omitted from the child environment", rec.Env["AUDITA_INHERITED_MARKER"])
}
}
func TestSubprocessRunnerOmitsModulesFlagWhenNotConfigured(t *testing.T) {
t.Setenv("GO_WANT_AUDITA_HELPER", "1")
t.Setenv("AUDITA_HELPER_MODE", "success")
recordPath := filepath.Join(t.TempDir(), "record.json")
t.Setenv("AUDITA_HELPER_RECORD_PATH", recordPath)
runner := mustAuditaRunner(t, SubprocessRunnerConfig{
Binary: writeAuditaHelperWrapper(t),
Timeout: mustParseAuditaDuration(t, "2s"),
LLMAPIKey: "",
BaseURL: "https://openrouter.ai/api/v1",
Model: "openrouter/google/gemma-4-31b-it",
Report: false,
})
req := auditaReqForTest(t, false)
if _, err := runner.Run(context.Background(), req); err != nil {
t.Fatalf("Run() error = %v", err)
}
rec := readAuditaHelperRecord(t, recordPath)
for i := 0; i < len(rec.Args); i++ {
if rec.Args[i] == "--modules" {
t.Fatalf("args contained --modules unexpectedly: %#v", rec.Args)
}
}
}
func TestSubprocessRunnerOmitsBaseURLAndModelFlagsWhenNotConfigured(t *testing.T) {
t.Setenv("GO_WANT_AUDITA_HELPER", "1")
t.Setenv("AUDITA_HELPER_MODE", "success")
recordPath := filepath.Join(t.TempDir(), "record.json")
t.Setenv("AUDITA_HELPER_RECORD_PATH", recordPath)
runner := mustAuditaRunner(t, SubprocessRunnerConfig{
Binary: writeAuditaHelperWrapper(t),
Timeout: mustParseAuditaDuration(t, "2s"),
LLMAPIKey: "",
Report: false,
})
req := auditaReqForTest(t, false)
if _, err := runner.Run(context.Background(), req); err != nil {
t.Fatalf("Run() error = %v", err)
}
rec := readAuditaHelperRecord(t, recordPath)
for i := 0; i < len(rec.Args); i++ {
if rec.Args[i] == "--base-url" {
t.Fatalf("args contained --base-url unexpectedly: %#v", rec.Args)
}
if rec.Args[i] == "--model" {
t.Fatalf("args contained --model unexpectedly: %#v", rec.Args)
}
}
}
func TestSubprocessRunnerSubprocessFailure(t *testing.T) {
t.Setenv("GO_WANT_AUDITA_HELPER", "1")
t.Setenv("AUDITA_HELPER_MODE", "fail")
t.Setenv("OPENAI_KEY_SOURCE", "super-secret")
t.Setenv("AUDITA_HELPER_RECORD_PATH", filepath.Join(t.TempDir(), "record.json"))
runner := mustAuditaRunner(t, SubprocessRunnerConfig{
Binary: writeAuditaHelperWrapper(t),
Timeout: mustParseAuditaDuration(t, "2s"),
LLMAPIKey: "super-secret",
LLMAPIKeyReference: "OPENAI_KEY_SOURCE",
Modules: []string{"glossary"},
BaseURL: "https://openrouter.ai/api/v1",
Model: "openrouter/google/gemma-4-31b-it",
Report: true,
})
req := auditaReqForTest(t, true)
_, err := runner.Run(context.Background(), req)
if err == nil {
t.Fatal("expected error, got nil")
}
if !strings.Contains(err.Error(), "run audita process") {
t.Fatalf("error = %q, want subprocess context", err.Error())
}
if !strings.Contains(err.Error(), "exit code") {
t.Fatalf("error = %q, want exit code context", err.Error())
}
if !strings.Contains(err.Error(), req.StdoutLogPath) || !strings.Contains(err.Error(), req.StderrLogPath) {
t.Fatalf("error = %q, want stdout/stderr log paths", err.Error())
}
if strings.Contains(err.Error(), "super-secret") {
t.Fatalf("failure diagnostic exposed credential value: %q", err.Error())
}
}
func TestSubprocessRunnerSubprocessFailureAddsStderrDescriptorHint(t *testing.T) {
t.Setenv("GO_WANT_AUDITA_HELPER", "1")
t.Setenv("AUDITA_HELPER_MODE", "fail_bad_fd")
t.Setenv("OPENAI_KEY_SOURCE", "super-secret")
t.Setenv("AUDITA_HELPER_RECORD_PATH", filepath.Join(t.TempDir(), "record.json"))
runner := mustAuditaRunner(t, SubprocessRunnerConfig{
Binary: writeAuditaHelperWrapper(t),
Timeout: mustParseAuditaDuration(t, "2s"),
LLMAPIKey: "super-secret",
LLMAPIKeyReference: "OPENAI_KEY_SOURCE",
Modules: []string{"glossary"},
BaseURL: "https://openrouter.ai/api/v1",
Model: "openrouter/google/gemma-4-31b-it",
Report: true,
})
req := auditaReqForTest(t, true)
_, err := runner.Run(context.Background(), req)
if err == nil {
t.Fatal("expected error, got nil")
}
if !strings.Contains(err.Error(), "hint=audita child process may have started with invalid stderr/stdout descriptors") {
t.Fatalf("error = %q, want stderr descriptor hint", err.Error())
}
}
func TestSubprocessRunnerMissingOutputFails(t *testing.T) {
t.Setenv("GO_WANT_AUDITA_HELPER", "1")
t.Setenv("AUDITA_HELPER_MODE", "missing_output")
t.Setenv("OPENAI_KEY_SOURCE", "super-secret")
t.Setenv("AUDITA_HELPER_RECORD_PATH", filepath.Join(t.TempDir(), "record.json"))
runner := mustAuditaRunner(t, SubprocessRunnerConfig{
Binary: writeAuditaHelperWrapper(t),
Timeout: mustParseAuditaDuration(t, "2s"),
LLMAPIKey: "super-secret",
LLMAPIKeyReference: "OPENAI_KEY_SOURCE",
Modules: []string{"glossary"},
BaseURL: "https://openrouter.ai/api/v1",
Model: "openrouter/google/gemma-4-31b-it",
Report: false,
})
req := auditaReqForTest(t, false)
_, err := runner.Run(context.Background(), req)
if err == nil {
t.Fatal("expected error, got nil")
}
if !strings.Contains(err.Error(), "validate audita processed output") {
t.Fatalf("error = %q, want output validation context", err.Error())
}
}
func TestSubprocessRunnerInvalidOutputJSONFails(t *testing.T) {
t.Setenv("GO_WANT_AUDITA_HELPER", "1")
t.Setenv("AUDITA_HELPER_MODE", "invalid_output")
t.Setenv("OPENAI_KEY_SOURCE", "super-secret")
t.Setenv("AUDITA_HELPER_RECORD_PATH", filepath.Join(t.TempDir(), "record.json"))
runner := mustAuditaRunner(t, SubprocessRunnerConfig{
Binary: writeAuditaHelperWrapper(t),
Timeout: mustParseAuditaDuration(t, "2s"),
LLMAPIKey: "super-secret",
LLMAPIKeyReference: "OPENAI_KEY_SOURCE",
Modules: []string{"glossary"},
BaseURL: "https://openrouter.ai/api/v1",
Model: "openrouter/google/gemma-4-31b-it",
Report: false,
})
req := auditaReqForTest(t, false)
_, err := runner.Run(context.Background(), req)
if err == nil {
t.Fatal("expected error, got nil")
}
if !strings.Contains(err.Error(), "parse json") {
t.Fatalf("error = %q, want parse json context", err.Error())
}
}
func TestSubprocessRunnerSegmentsMissingFails(t *testing.T) {
t.Setenv("GO_WANT_AUDITA_HELPER", "1")
t.Setenv("AUDITA_HELPER_MODE", "segments_missing")
t.Setenv("OPENAI_KEY_SOURCE", "super-secret")
t.Setenv("AUDITA_HELPER_RECORD_PATH", filepath.Join(t.TempDir(), "record.json"))
runner := mustAuditaRunner(t, SubprocessRunnerConfig{
Binary: writeAuditaHelperWrapper(t),
Timeout: mustParseAuditaDuration(t, "2s"),
LLMAPIKey: "super-secret",
LLMAPIKeyReference: "OPENAI_KEY_SOURCE",
Modules: []string{"glossary"},
BaseURL: "https://openrouter.ai/api/v1",
Model: "openrouter/google/gemma-4-31b-it",
Report: false,
})
req := auditaReqForTest(t, false)
_, err := runner.Run(context.Background(), req)
if err == nil {
t.Fatal("expected error, got nil")
}
if !strings.Contains(err.Error(), "segments") {
t.Fatalf("error = %q, want segments validation context", err.Error())
}
}
func TestSubprocessRunnerInvalidReportJSONFails(t *testing.T) {
t.Setenv("GO_WANT_AUDITA_HELPER", "1")
t.Setenv("AUDITA_HELPER_MODE", "invalid_report")
t.Setenv("OPENAI_KEY_SOURCE", "super-secret")
t.Setenv("AUDITA_HELPER_RECORD_PATH", filepath.Join(t.TempDir(), "record.json"))
runner := mustAuditaRunner(t, SubprocessRunnerConfig{
Binary: writeAuditaHelperWrapper(t),
Timeout: mustParseAuditaDuration(t, "2s"),
LLMAPIKey: "super-secret",
LLMAPIKeyReference: "OPENAI_KEY_SOURCE",
Modules: []string{"glossary"},
BaseURL: "https://openrouter.ai/api/v1",
Model: "openrouter/google/gemma-4-31b-it",
Report: true,
})
req := auditaReqForTest(t, true)
_, err := runner.Run(context.Background(), req)
if err == nil {
t.Fatal("expected error, got nil")
}
if !strings.Contains(err.Error(), "validate audita report output") {
t.Fatalf("error = %q, want report validation context", err.Error())
}
}
func TestSubprocessRunnerConstructorValidation(t *testing.T) {
_, err := NewSubprocessRunnerFromConfigValues("", "3h", "synthetic-secret", "AUDITA_LLM_API_KEY", []string{"glossary"}, "https://openrouter.ai/api/v1", "openrouter/google/gemma-4-31b-it", "", "", "", "", nil, nil, "", nil, true)
if err == nil {
t.Fatal("expected binary validation error")
}
_, err = NewSubprocessRunnerFromConfigValues("audita", "bad", "synthetic-secret", "AUDITA_LLM_API_KEY", []string{"glossary"}, "https://openrouter.ai/api/v1", "openrouter/google/gemma-4-31b-it", "", "", "", "", nil, nil, "", nil, true)
if err == nil {
t.Fatal("expected timeout parse error")
}
_, err = NewSubprocessRunner(SubprocessRunnerConfig{
Binary: "audita",
Timeout: mustParseAuditaDuration(t, "1s"),
LLMAPIKey: "synthetic-secret",
LLMAPIKeyReference: "AUDITA_LLM_API_KEY",
Modules: []string{"glossary"},
BaseURL: "://",
Model: "openrouter/google/gemma-4-31b-it",
})
if err == nil {
t.Fatal("expected base url validation error")
}
}
type auditaHelperRecord struct {
Args []string `json:"args"`
Env map[string]string `json:"env"`
}
func TestAuditaSubprocessHelper(t *testing.T) {
if os.Getenv("GO_WANT_AUDITA_HELPER") != "1" {
return
}
args := os.Args
start := -1
for i := range args {
if args[i] == "--" {
start = i + 1
break
}
}
if start < 0 || start >= len(args) {
_, _ = os.Stderr.WriteString("missing -- args separator\n")
os.Exit(2)
}
procArgs := args[start:]
outPath := auditaFlagValue(procArgs, "--output")
reportPath := auditaFlagValue(procArgs, "--report-json")
recordPath := os.Getenv("AUDITA_HELPER_RECORD_PATH")
if strings.TrimSpace(recordPath) != "" {
rec := auditaHelperRecord{
Args: procArgs,
Env: map[string]string{
"AUDITA_LLM_API_KEY": os.Getenv("AUDITA_LLM_API_KEY"),
"AUDITA_LLM_CONCURRENCY": os.Getenv("AUDITA_LLM_CONCURRENCY"),
"AUDITA_INHERITED_MARKER": os.Getenv("AUDITA_INHERITED_MARKER"),
},
}
data, _ := json.Marshal(rec)
_ = os.MkdirAll(filepath.Dir(recordPath), 0o755)
_ = os.WriteFile(recordPath, data, 0o644)
}
mode := os.Getenv("AUDITA_HELPER_MODE")
switch mode {
case "success":
writeAuditaHelperFile(outPath, `{"schema":"audita.processed.v1","segments":[]}`)
if reportPath != "" {
writeAuditaHelperFile(reportPath, `{"schema":"audita.report.v1","steps":[]}`)
}
_, _ = os.Stdout.WriteString("audita helper success stdout\n")
_, _ = os.Stderr.WriteString("audita helper success stderr\n")
os.Exit(0)
case "fail":
_, _ = os.Stderr.WriteString("audita helper failure\n")
os.Exit(8)
case "fail_bad_fd":
_, _ = os.Stderr.WriteString("OSError: [Errno 9] Bad file descriptor\n")
os.Exit(120)
case "missing_output":
if reportPath != "" {
writeAuditaHelperFile(reportPath, `{"schema":"audita.report.v1","steps":[]}`)
}
os.Exit(0)
case "invalid_output":
writeAuditaHelperFile(outPath, `not-json`)
if reportPath != "" {
writeAuditaHelperFile(reportPath, `{"schema":"audita.report.v1","steps":[]}`)
}
os.Exit(0)
case "segments_missing":
writeAuditaHelperFile(outPath, `{"schema":"audita.processed.v1"}`)
if reportPath != "" {
writeAuditaHelperFile(reportPath, `{"schema":"audita.report.v1","steps":[]}`)
}
os.Exit(0)
case "invalid_report":
writeAuditaHelperFile(outPath, `{"schema":"audita.processed.v1","segments":[]}`)
if reportPath != "" {
writeAuditaHelperFile(reportPath, `not-json`)
}
os.Exit(0)
default:
_, _ = os.Stderr.WriteString(fmt.Sprintf("unknown helper mode %q\n", mode))
os.Exit(2)
}
}
func mustAuditaRunner(t *testing.T, cfg SubprocessRunnerConfig) *SubprocessRunner {
t.Helper()
r, err := NewSubprocessRunner(cfg)
if err != nil {
t.Fatalf("NewSubprocessRunner() error = %v", err)
}
return r
}
func auditaReqForTest(t *testing.T, withReport bool) PolishRequest {
t.Helper()
dir := t.TempDir()
merged := filepath.Join(dir, "base.json")
glossary := filepath.Join(dir, "glossary.yml")
writeAuditaTestFile(t, merged, `{"segments":[]}`)
writeAuditaTestFile(t, glossary, "terms: []\n")
req := PolishRequest{
GeneratedConfigPath: filepath.Join(dir, "audita.generated.yml"), GeneratedConfigPath: filepath.Join(dir, "audita.generated.yml"),
MergedTranscriptPath: merged, StdoutLogPath: filepath.Join(dir, "stdout.log"),
GlossaryPath: glossary, StderrLogPath: filepath.Join(dir, "stderr.log"),
OutputProcessedPath: filepath.Join(dir, "polished.json"),
WorkDir: filepath.Join(dir, "artifacts", "audita-work"),
StdoutLogPath: filepath.Join(dir, "audita.stdout.log"),
StderrLogPath: filepath.Join(dir, "audita.stderr.log"),
} }
if withReport {
req.ReportPath = filepath.Join(dir, "audita.report.json")
}
return req
} }
func writeAuditaHelperWrapper(t *testing.T) string { func auditaTestRunner(t *testing.T, cfg SubprocessRunnerConfig) *SubprocessRunner {
t.Helper() t.Helper()
exe, err := os.Executable() if cfg.Binary == "" {
cfg.Binary = "audita"
}
if cfg.Timeout == 0 {
cfg.Timeout = time.Second
}
runner, err := NewSubprocessRunner(cfg)
if err != nil { if err != nil {
t.Fatalf("os.Executable() error = %v", err) t.Fatal(err)
} }
path := filepath.Join(t.TempDir(), "audita-helper-wrapper.sh") return runner
content := "#!/bin/sh\nexec \"" + exe + "\" -test.run=TestAuditaSubprocessHelper -- \"$@\"\n"
if err := os.WriteFile(path, []byte(content), 0o755); err != nil {
t.Fatalf("WriteFile(%q) error = %v", path, err)
}
return path
} }
func writeAuditaTestFile(t *testing.T, path, contents string) { func auditaTestSecret(t *testing.T, name, value string) configkit.Secret {
t.Helper() t.Helper()
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { t.Setenv(name, value)
t.Fatalf("MkdirAll(%q): %v", path, err) type loaded struct {
Credential configkit.Secret `yaml:"credential"`
} }
if err := os.WriteFile(path, []byte(contents), 0o644); err != nil { result, err := configkit.Load(configkit.Bytes("credential.yml", []byte("credential: "+name+"\n")), configkit.Options[loaded]{})
t.Fatalf("WriteFile(%q): %v", path, err) if err != nil {
t.Fatal(err)
}
return result.Config.Credential
}
func writeAuditaTestFile(t *testing.T, path, value string) {
t.Helper()
if err := os.WriteFile(path, []byte(value), 0o600); err != nil {
t.Fatal(err)
} }
} }
func writeAuditaHelperFile(path, contents string) { func TestSubprocessRunnerUsesV2InvocationAndCapturedCredentials(t *testing.T) {
if strings.TrimSpace(path) == "" { const first = "NARRATIO_AUDITA_CUSTOM_ONE"
return const second = "NARRATIO_AUDITA_CUSTOM_TWO"
} firstSecret := auditaTestSecret(t, first, "loaded-one")
_ = os.MkdirAll(filepath.Dir(path), 0o755) secondSecret := auditaTestSecret(t, second, "loaded-two")
_ = os.WriteFile(path, []byte(contents), 0o644) t.Setenv(first, "parent-changed")
} t.Setenv(second, "parent-changed-too")
t.Setenv("NARRATIO_AUDITA_UNSELECTED", "not-forwarded")
func auditaFlagValue(args []string, name string) string { runner := auditaTestRunner(t, SubprocessRunnerConfig{
for i := 0; i < len(args)-1; i++ { Credentials: []configkit.Secret{firstSecret, secondSecret},
if args[i] == name { Modules: []string{"grammar", "glossary", "grammar"},
return args[i+1] Overlay: "testing", ProposalProfile: "proposal", ValidationProfile: "validation",
TranscriptDescription: "campaign", ConfigPath: "/etc/audita/config.yml", OutputSchema: "audita-v1",
})
req := auditaTestRequest(t)
var captured subprocess.RunRequest
runner.run = func(_ context.Context, processReq subprocess.RunRequest) (subprocess.RunResult, error) {
captured = processReq
writeAuditaTestFile(t, req.OutputProcessedPath, `{"segments":[]}`)
for _, name := range []string{"errors.yml", "recoveries.yml", "report.md"} {
writeAuditaTestFile(t, filepath.Join(filepath.Dir(req.OutputProcessedPath), name), "recoverable diagnostic\n")
} }
return subprocess.RunResult{}, nil
} }
return "" result, err := runner.Run(context.Background(), req)
}
func readAuditaHelperRecord(t *testing.T, path string) auditaHelperRecord {
t.Helper()
data, err := os.ReadFile(path)
if err != nil { if err != nil {
t.Fatalf("ReadFile(%q): %v", path, err) t.Fatal(err)
} }
var rec auditaHelperRecord want := []string{"process", req.MergedTranscriptPath, "--glossary", req.GlossaryPath, "--output", req.OutputProcessedPath,
if err := json.Unmarshal(data, &rec); err != nil { "--modules", "grammar,glossary,grammar", "--config", "/etc/audita/config.yml", "--overlay", "testing",
t.Fatalf("json unmarshal helper record: %v", err) "--proposal-profile", "proposal", "--validation-profile", "validation", "--transcript-description", "campaign", "--output-schema", "audita-v1"}
if !reflect.DeepEqual(captured.Args, want) {
t.Fatalf("args = %#v, want %#v", captured.Args, want)
} }
return rec if len(captured.EnvOverrides) != 2 || captured.EnvOverrides[first] != "loaded-one" || captured.EnvOverrides[second] != "loaded-two" || captured.EnvOverrides["NARRATIO_AUDITA_UNSELECTED"] != "" {
} t.Fatalf("credential forwarding = %#v", captured.EnvOverrides)
}
func assertJSONFileAudita(t *testing.T, path string) { if !reflect.DeepEqual(captured.SensitiveEnvNames, []string{first, second}) {
t.Helper() t.Fatalf("sensitive names = %#v", captured.SensitiveEnvNames)
data, err := os.ReadFile(path) }
if result.Reports.ErrorsPath == "" || result.Reports.RecoveriesPath == "" || result.Reports.OverviewPath == "" {
t.Fatalf("reports = %#v", result.Reports)
}
generated, err := os.ReadFile(req.GeneratedConfigPath)
if err != nil { if err != nil {
t.Fatalf("ReadFile(%q): %v", path, err) t.Fatal(err)
} }
var v any if !strings.Contains(string(generated), "audita.generated.v2") || !strings.Contains(string(generated), first) || strings.Contains(string(generated), "loaded-one") {
if err := json.Unmarshal(data, &v); err != nil { t.Fatalf("unsafe or incomplete generated invocation: %s", generated)
t.Fatalf("json unmarshal %q: %v", path, err)
} }
} }
func mustParseAuditaDuration(t *testing.T, value string) time.Duration { func TestSubprocessRunnerModulePresenceAndReportAbsence(t *testing.T) {
t.Helper() for _, test := range []struct {
d, err := time.ParseDuration(value) name string
if err != nil { configured []string
t.Fatalf("time.ParseDuration(%q) error = %v", value, err) requested []string
wantFlag bool
wantValue string
}{
{"omitted", nil, nil, false, ""},
{"configured", []string{"grammar", "grammar"}, nil, true, "grammar,grammar"},
{"empty override", []string{"grammar"}, []string{}, true, ""},
} {
t.Run(test.name, func(t *testing.T) {
runner := auditaTestRunner(t, SubprocessRunnerConfig{Modules: test.configured})
req := auditaTestRequest(t)
req.Modules = test.requested
runner.run = func(_ context.Context, processReq subprocess.RunRequest) (subprocess.RunResult, error) {
index := -1
for i, arg := range processReq.Args {
if arg == "--modules" {
index = i
}
if strings.HasPrefix(arg, "--report") || arg == "--debug" || arg == "--work-dir" {
t.Fatalf("retired or unwanted flag %q", arg)
}
}
if (index >= 0) != test.wantFlag || (index >= 0 && processReq.Args[index+1] != test.wantValue) {
t.Fatalf("args = %#v", processReq.Args)
}
writeAuditaTestFile(t, req.OutputProcessedPath, `{"segments":[]}`)
return subprocess.RunResult{}, nil
}
result, err := runner.Run(context.Background(), req)
if err != nil || result.Reports != (ReportBundle{}) {
t.Fatalf("result = %#v, error = %v", result, err)
}
})
}
}
func TestSubprocessRunnerRejectsMissingOrMalformedTranscript(t *testing.T) {
for _, output := range []string{"", `{"segments":"wrong"}`} {
t.Run(output, func(t *testing.T) {
runner := auditaTestRunner(t, SubprocessRunnerConfig{})
req := auditaTestRequest(t)
runner.run = func(context.Context, subprocess.RunRequest) (subprocess.RunResult, error) {
if output != "" {
writeAuditaTestFile(t, req.OutputProcessedPath, output)
}
return subprocess.RunResult{}, nil
}
if _, err := runner.Run(context.Background(), req); err == nil {
t.Fatal("missing or malformed transcript was accepted")
}
})
}
}
func TestSubprocessRunnerPreservesFailureAndAvailableReports(t *testing.T) {
runner := auditaTestRunner(t, SubprocessRunnerConfig{})
req := auditaTestRequest(t)
processFailure := errors.New("audita exited after writing output")
runner.run = func(context.Context, subprocess.RunRequest) (subprocess.RunResult, error) {
writeAuditaTestFile(t, req.OutputProcessedPath, `{"segments":[]}`)
writeAuditaTestFile(t, filepath.Join(filepath.Dir(req.OutputProcessedPath), "errors.yml"), "status: failed\n")
return subprocess.RunResult{ExitCode: 7}, processFailure
}
result, err := runner.Run(context.Background(), req)
if !errors.Is(err, processFailure) || !strings.Contains(err.Error(), filepath.Dir(req.OutputProcessedPath)) {
t.Fatalf("error = %v", err)
}
if result.Reports.ErrorsPath == "" || result.Reports.RecoveriesPath != "" || result.Reports.OverviewPath != "" {
t.Fatalf("reports = %#v", result.Reports)
}
}
func TestSubprocessRunnerDoesNotMaskProcessFailureWithReportError(t *testing.T) {
runner := auditaTestRunner(t, SubprocessRunnerConfig{})
req := auditaTestRequest(t)
processFailure := errors.New("audita process failed")
runner.run = func(context.Context, subprocess.RunRequest) (subprocess.RunResult, error) {
path := filepath.Join(filepath.Dir(req.OutputProcessedPath), "errors.yml")
if err := os.WriteFile(path, make([]byte, MaxReportOutputBytes+1), 0o600); err != nil {
t.Fatal(err)
}
return subprocess.RunResult{ExitCode: 7}, processFailure
}
if _, err := runner.Run(context.Background(), req); !errors.Is(err, processFailure) {
t.Fatalf("error = %v, want original process error", err)
}
}
func TestSubprocessRunnerBoundsAdjacentReports(t *testing.T) {
runner := auditaTestRunner(t, SubprocessRunnerConfig{})
req := auditaTestRequest(t)
runner.run = func(context.Context, subprocess.RunRequest) (subprocess.RunResult, error) {
writeAuditaTestFile(t, req.OutputProcessedPath, `{"segments":[]}`)
path := filepath.Join(filepath.Dir(req.OutputProcessedPath), "errors.yml")
if err := os.WriteFile(path, make([]byte, MaxReportOutputBytes+1), 0o600); err != nil {
t.Fatal(err)
}
return subprocess.RunResult{}, nil
}
if _, err := runner.Run(context.Background(), req); err == nil || !strings.Contains(err.Error(), "errors.yml") || !strings.Contains(err.Error(), "16777216") {
t.Fatalf("error = %v, want named report limit", err)
}
}
func TestSubprocessRunnerRedactsCustomCredentialStreams(t *testing.T) {
const first = "NARRATIO_AUDITA_STREAM_ONE"
const second = "NARRATIO_AUDITA_STREAM_TWO"
for _, fail := range []bool{false, true} {
t.Run(map[bool]string{false: "success", true: "failure"}[fail], func(t *testing.T) {
firstSecret := auditaTestSecret(t, first, "audita-first-secret")
secondSecret := auditaTestSecret(t, second, "audita-second-secret")
req := auditaTestRequest(t)
body := "#!/bin/sh\nprintf '%s\\n' \"$" + first + "\"\nprintf '%s\\n' \"$" + second + "\" >&2\n"
if fail {
body += "exit 7\n"
} else {
body += "printf '{\"segments\":[]}' > \"" + req.OutputProcessedPath + "\"\n"
}
binary := filepath.Join(t.TempDir(), "audita-helper")
writeAuditaTestFile(t, binary, body)
if err := os.Chmod(binary, 0o700); err != nil {
t.Fatal(err)
}
runner := auditaTestRunner(t, SubprocessRunnerConfig{Binary: binary, Credentials: []configkit.Secret{firstSecret, secondSecret}})
_, err := runner.Run(context.Background(), req)
if (err != nil) != fail {
t.Fatalf("error = %v, fail = %v", err, fail)
}
for _, path := range []string{req.StdoutLogPath, req.StderrLogPath} {
data, readErr := os.ReadFile(path)
if readErr != nil {
t.Fatal(readErr)
}
if strings.Contains(string(data), "audita-first-secret") || strings.Contains(string(data), "audita-second-secret") || !strings.Contains(string(data), "<redacted>") {
t.Fatalf("unredacted stream %q: %s", path, data)
}
}
if fail && (strings.Contains(err.Error(), "audita-first-secret") || strings.Contains(err.Error(), "audita-second-secret")) {
t.Fatalf("unredacted failure: %v", err)
}
})
} }
return d
} }

View File

@@ -1,6 +1,10 @@
package notarius package notarius
import "context" import (
"context"
configkit "gitea.maximumdirect.net/eric/ConfigKit"
)
// FakeRunner is a configurable in-memory runner for stage tests. // FakeRunner is a configurable in-memory runner for stage tests.
type FakeRunner struct { type FakeRunner struct {
@@ -15,6 +19,7 @@ func (f *FakeRunner) Run(ctx context.Context, req RunRequest) (RunResult, error)
return RunResult{}, err return RunResult{}, err
} }
copyRequest := req copyRequest := req
copyRequest.Credentials = append([]configkit.Secret(nil), req.Credentials...)
if req.ConfigProfile != nil { if req.ConfigProfile != nil {
profile := *req.ConfigProfile profile := *req.ConfigProfile
copyRequest.ConfigProfile = &profile copyRequest.ConfigProfile = &profile

View File

@@ -25,8 +25,8 @@ type ReferenceBinding struct {
// RunRequest contains the resolved inputs and diagnostic destinations for one invocation. // RunRequest contains the resolved inputs and diagnostic destinations for one invocation.
type RunRequest struct { type RunRequest struct {
Binary string Binary string
// LLMAPIKey is an optional already-resolved credential reference. // Credentials are already-resolved environment references selected for Notarius.
LLMAPIKey *configkit.Secret Credentials []configkit.Secret
ConfigProfile *string ConfigProfile *string
ConfigPath string ConfigPath string
PipelineID string PipelineID string

View File

@@ -52,19 +52,9 @@ func (r *SubprocessRunner) Run(ctx context.Context, req RunRequest) (RunResult,
if err != nil { if err != nil {
return RunResult{}, err return RunResult{}, err
} }
var envOverrides map[string]string envOverrides, sensitiveEnvNames, err := subprocess.CredentialEnvironment(req.Credentials)
var sensitiveEnvNames []string if err != nil {
if req.LLMAPIKey != nil { return RunResult{}, fmt.Errorf("notarius credentials: %w", err)
if !req.LLMAPIKey.IsResolved() {
return RunResult{}, fmt.Errorf("notarius LLM API credential must be resolved and nonempty")
}
name := req.LLMAPIKey.EnvName()
value := req.LLMAPIKey.Value()
if value == "" {
return RunResult{}, fmt.Errorf("notarius LLM API credential must be resolved and nonempty")
}
envOverrides = map[string]string{name: value}
sensitiveEnvNames = []string{name}
} }
args := []string{ args := []string{

View File

@@ -188,12 +188,16 @@ func TestSubprocessRunnerRejectsInvalidChunkCacheBeforeLaunch(t *testing.T) {
func TestSubprocessRunnerForwardsLoadedCredentialWithoutRereadingEnvironment(t *testing.T) { func TestSubprocessRunnerForwardsLoadedCredentialWithoutRereadingEnvironment(t *testing.T) {
const envName = "NARRATIO_NOTARIUS_CUSTOM_LLM_KEY" const envName = "NARRATIO_NOTARIUS_CUSTOM_LLM_KEY"
const otherName = "NARRATIO_NOTARIUS_CUSTOM_OTHER_KEY"
const loadedValue = "loaded-notarius-credential" const loadedValue = "loaded-notarius-credential"
const otherValue = "loaded-notarius-other-credential"
credential := loadTestCredential(t, envName, loadedValue) credential := loadTestCredential(t, envName, loadedValue)
otherCredential := loadTestCredential(t, otherName, otherValue)
t.Setenv(envName, "changed-parent-credential") t.Setenv(envName, "changed-parent-credential")
t.Setenv(otherName, "changed-parent-other-credential")
req := validRunRequest(t) req := validRunRequest(t)
req.LLMAPIKey = credential req.Credentials = []configkit.Secret{*credential, *otherCredential}
var captured sharedsubprocess.RunRequest var captured sharedsubprocess.RunRequest
runner := &SubprocessRunner{run: func(_ context.Context, processReq sharedsubprocess.RunRequest) (sharedsubprocess.RunResult, error) { runner := &SubprocessRunner{run: func(_ context.Context, processReq sharedsubprocess.RunRequest) (sharedsubprocess.RunResult, error) {
captured = processReq captured = processReq
@@ -203,10 +207,10 @@ func TestSubprocessRunnerForwardsLoadedCredentialWithoutRereadingEnvironment(t *
if _, err := runner.Run(context.Background(), req); err != nil { if _, err := runner.Run(context.Background(), req); err != nil {
t.Fatalf("Run() error = %v", err) t.Fatalf("Run() error = %v", err)
} }
if len(captured.EnvOverrides) != 1 || captured.EnvOverrides[envName] != loadedValue { if len(captured.EnvOverrides) != 2 || captured.EnvOverrides[envName] != loadedValue || captured.EnvOverrides[otherName] != otherValue {
t.Fatal("subprocess did not receive exactly the loaded credential override") t.Fatal("subprocess did not receive exactly the loaded credential overrides")
} }
if !reflect.DeepEqual(captured.SensitiveEnvNames, []string{envName}) { if !reflect.DeepEqual(captured.SensitiveEnvNames, []string{envName, otherName}) {
t.Fatalf("sensitive environment names = %#v, want configured reference name", captured.SensitiveEnvNames) t.Fatalf("sensitive environment names = %#v, want configured reference name", captured.SensitiveEnvNames)
} }
wantArgs := []string{ wantArgs := []string{
@@ -228,7 +232,7 @@ func TestSubprocessRunnerRejectsInvalidProgrammaticCredentialBeforeLaunch(t *tes
} { } {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
req := validRunRequest(t) req := validRunRequest(t)
req.LLMAPIKey = &test.reference req.Credentials = []configkit.Secret{test.reference}
started := false started := false
runner := &SubprocessRunner{run: func(context.Context, sharedsubprocess.RunRequest) (sharedsubprocess.RunResult, error) { runner := &SubprocessRunner{run: func(context.Context, sharedsubprocess.RunRequest) (sharedsubprocess.RunResult, error) {
started = true started = true
@@ -342,10 +346,12 @@ func TestSubprocessRunnerRejectsInvalidReferencesBeforeLaunch(t *testing.T) {
func TestSubprocessRunnerUsesMinimalEnvironmentAndSeparatesStreams(t *testing.T) { func TestSubprocessRunnerUsesMinimalEnvironmentAndSeparatesStreams(t *testing.T) {
const envName = "NARRATIO_NOTARIUS_CUSTOM_CAPTURE_KEY" const envName = "NARRATIO_NOTARIUS_CUSTOM_CAPTURE_KEY"
const otherName = "NARRATIO_NOTARIUS_CUSTOM_CAPTURE_OTHER_KEY"
const canary = "notarius-captured-stream-canary" const canary = "notarius-captured-stream-canary"
const otherCanary = "notarius-captured-stream-other-canary"
const unrelated = "NARRATIO_NOTARIUS_UNRELATED_PARENT_KEY" const unrelated = "NARRATIO_NOTARIUS_UNRELATED_PARENT_KEY"
req := validRunRequest(t) req := validRunRequest(t)
req.LLMAPIKey = loadTestCredential(t, envName, canary) req.Credentials = []configkit.Secret{*loadTestCredential(t, envName, canary), *loadTestCredential(t, otherName, otherCanary)}
writeValidBundleAndReceipt(t, req, false) writeValidBundleAndReceipt(t, req, false)
receiptFixture := req.ReceiptPath + ".fixture" receiptFixture := req.ReceiptPath + ".fixture"
data, err := os.ReadFile(req.ReceiptPath) data, err := os.ReadFile(req.ReceiptPath)
@@ -356,7 +362,7 @@ func TestSubprocessRunnerUsesMinimalEnvironmentAndSeparatesStreams(t *testing.T)
if err := json.Unmarshal(data, &receipt); err != nil { if err := json.Unmarshal(data, &receipt); err != nil {
t.Fatalf("decode receipt fixture: %v", err) t.Fatalf("decode receipt fixture: %v", err)
} }
receipt["credential_echo"] = canary receipt["credential_echo"] = canary + " " + otherCanary
writeJSONFile(t, receiptFixture, receipt) writeJSONFile(t, receiptFixture, receipt)
if err := os.Remove(req.ReceiptPath); err != nil { if err := os.Remove(req.ReceiptPath); err != nil {
t.Fatalf("Remove(receipt) error = %v", err) t.Fatalf("Remove(receipt) error = %v", err)
@@ -373,11 +379,16 @@ if [ "$`+envName+`" != '`+canary+`' ]; then
printf 'selected credential mismatch\n' >&2 printf 'selected credential mismatch\n' >&2
exit 8 exit 8
fi fi
if [ "$`+otherName+`" != '`+otherCanary+`' ]; then
printf 'other selected credential mismatch\n' >&2
exit 10
fi
if [ -n "$`+unrelated+`" ]; then if [ -n "$`+unrelated+`" ]; then
printf 'unrelated credential inherited\n' >&2 printf 'unrelated credential inherited\n' >&2
exit 9 exit 9
fi fi
printf '%s\n' "$`+envName+`" >&2 printf '%s\n' "$`+envName+`" >&2
printf '%s\n' "$`+otherName+`" >&2
cat "$NOTARIUS_RECEIPT_FIXTURE" cat "$NOTARIUS_RECEIPT_FIXTURE"
`) `)
req.Binary = script req.Binary = script
@@ -392,32 +403,39 @@ cat "$NOTARIUS_RECEIPT_FIXTURE"
assertTextFile(t, filepath.Join(captureDir, "working-directory"), req.WorkingDirectory+"\n") assertTextFile(t, filepath.Join(captureDir, "working-directory"), req.WorkingDirectory+"\n")
assertTextFile(t, filepath.Join(captureDir, "environment"), "") assertTextFile(t, filepath.Join(captureDir, "environment"), "")
assertRedactedCredentialFile(t, req.LogPath, canary) assertRedactedCredentialFile(t, req.LogPath, canary)
assertRedactedCredentialFile(t, req.LogPath, otherCanary)
receiptBytes, err := os.ReadFile(req.ReceiptPath) receiptBytes, err := os.ReadFile(req.ReceiptPath)
if err != nil { if err != nil {
t.Fatalf("ReadFile(receipt) error = %v", err) t.Fatalf("ReadFile(receipt) error = %v", err)
} }
assertRedactedCredentialBytes(t, receiptBytes, canary) assertRedactedCredentialBytes(t, receiptBytes, canary)
assertRedactedCredentialBytes(t, receiptBytes, otherCanary)
} }
func TestSubprocessRunnerRedactsCredentialOnProcessFailure(t *testing.T) { func TestSubprocessRunnerRedactsCredentialOnProcessFailure(t *testing.T) {
const envName = "NARRATIO_NOTARIUS_CUSTOM_FAILURE_KEY" const envName = "NARRATIO_NOTARIUS_CUSTOM_FAILURE_KEY"
const otherName = "NARRATIO_NOTARIUS_CUSTOM_FAILURE_OTHER_KEY"
const canary = "notarius-failure-stream-canary" const canary = "notarius-failure-stream-canary"
const otherCanary = "notarius-failure-stream-other-canary"
req := validRunRequest(t) req := validRunRequest(t)
req.LLMAPIKey = loadTestCredential(t, envName, canary) req.Credentials = []configkit.Secret{*loadTestCredential(t, envName, canary), *loadTestCredential(t, otherName, otherCanary)}
req.Binary = writeShellScript(t, `#!/bin/sh req.Binary = writeShellScript(t, `#!/bin/sh
printf '%s\n' "$`+envName+`" printf '%s\n' "$`+envName+`"
printf '%s\n' "$`+envName+`" >&2 printf '%s\n' "$`+envName+`" >&2
printf '%s\n' "$`+otherName+`" >&2
exit 7 exit 7
`) `)
_, err := NewSubprocessRunner().Run(context.Background(), req) _, err := NewSubprocessRunner().Run(context.Background(), req)
if err == nil { if err == nil {
t.Fatal("Run() error = nil, want process failure") t.Fatal("Run() error = nil, want process failure")
} }
if strings.Contains(err.Error(), canary) || !strings.Contains(err.Error(), "<redacted>") { if strings.Contains(err.Error(), canary) || strings.Contains(err.Error(), otherCanary) || !strings.Contains(err.Error(), "<redacted>") {
t.Fatal("process failure did not return redacted diagnostics") t.Fatal("process failure did not return redacted diagnostics")
} }
assertRedactedCredentialFile(t, req.ReceiptPath, canary) assertRedactedCredentialFile(t, req.ReceiptPath, canary)
assertRedactedCredentialFile(t, req.ReceiptPath, otherCanary)
assertRedactedCredentialFile(t, req.LogPath, canary) assertRedactedCredentialFile(t, req.LogPath, canary)
assertRedactedCredentialFile(t, req.LogPath, otherCanary)
} }
func TestSubprocessRunnerReturnsProcessFailuresWithoutParsingStdout(t *testing.T) { func TestSubprocessRunnerReturnsProcessFailuresWithoutParsingStdout(t *testing.T) {

View File

@@ -0,0 +1,29 @@
package subprocess
import (
"fmt"
configkit "gitea.maximumdirect.net/eric/ConfigKit"
)
// CredentialEnvironment returns captured secret values and names for a child
// invocation. References must already have been resolved by ConfigKit.
func CredentialEnvironment(credentials []configkit.Secret) (map[string]string, []string, error) {
if len(credentials) == 0 {
return nil, nil, nil
}
overrides := make(map[string]string, len(credentials))
names := make([]string, 0, len(credentials))
for _, credential := range credentials {
name := credential.EnvName()
value := credential.Value()
if !credential.IsResolved() || value == "" {
return nil, nil, fmt.Errorf("credential %q must be resolved and nonempty", name)
}
if _, exists := overrides[name]; !exists {
names = append(names, name)
overrides[name] = value
}
}
return overrides, names, nil
}

View File

@@ -0,0 +1,51 @@
package subprocess
import (
"reflect"
"testing"
configkit "gitea.maximumdirect.net/eric/ConfigKit"
)
func TestCredentialEnvironmentUsesCapturedReferences(t *testing.T) {
t.Setenv("CUSTOM_ALPHA_KEY", "alpha-value")
t.Setenv("SECOND_PROVIDER_TOKEN", "second-value")
t.Setenv("UNSELECTED_SECRET", "unselected-value")
type configuration struct {
Credentials []configkit.Secret `yaml:"credentials"`
}
loaded, err := configkit.Load[configuration](configkit.Bytes("credentials.yml", []byte("credentials: [CUSTOM_ALPHA_KEY, SECOND_PROVIDER_TOKEN, CUSTOM_ALPHA_KEY]\n")))
if err != nil {
t.Fatal(err)
}
t.Setenv("CUSTOM_ALPHA_KEY", "later-value")
overrides, names, err := CredentialEnvironment(loaded.Config.Credentials)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(overrides, map[string]string{"CUSTOM_ALPHA_KEY": "alpha-value", "SECOND_PROVIDER_TOKEN": "second-value"}) ||
!reflect.DeepEqual(names, []string{"CUSTOM_ALPHA_KEY", "SECOND_PROVIDER_TOKEN"}) {
t.Fatalf("credential selection = %#v, %#v", overrides, names)
}
overrides["CUSTOM_ALPHA_KEY"] = "modified"
names[0] = "modified"
again, againNames, err := CredentialEnvironment(loaded.Config.Credentials)
if err != nil || again["CUSTOM_ALPHA_KEY"] != "alpha-value" || againNames[0] != "CUSTOM_ALPHA_KEY" {
t.Fatalf("credential conversion retained mutable result: %#v, %#v, %v", again, againNames, err)
}
}
func TestCredentialEnvironmentHandlesEmptyAndUnresolvedReferences(t *testing.T) {
for _, credentials := range [][]configkit.Secret{nil, {}} {
overrides, names, err := CredentialEnvironment(credentials)
if err != nil || len(overrides) != 0 || len(names) != 0 {
t.Fatalf("empty credentials = %#v, %#v, %v", overrides, names, err)
}
}
for _, credentials := range [][]configkit.Secret{{configkit.SecretEnv("UNRESOLVED_KEY")}, {{}}} {
overrides, names, err := CredentialEnvironment(credentials)
if err == nil || overrides != nil || names != nil {
t.Fatalf("unresolved credentials = %#v, %#v, %v", overrides, names, err)
}
}
}

View File

@@ -256,12 +256,12 @@ func TestAssembledSplitBundleCommandsUseOneEffectiveFamilyConfiguration(t *testi
if err := ConfigValidate(context.Background(), []string{"--config", pipelinePath, "--campaign-file", campaignPath}, &validated); err != nil { if err := ConfigValidate(context.Background(), []string{"--config", pipelinePath, "--campaign-file", campaignPath}, &validated); err != nil {
t.Fatalf("validate production base: %v", err) t.Fatalf("validate production base: %v", err)
} }
if !strings.Contains(validated.String(), "profile=none") { if !strings.Contains(validated.String(), "overlay=none") {
t.Fatalf("validate output = %q, want unprofiled production base", validated.String()) t.Fatalf("validate output = %q, want production base", validated.String())
} }
for _, command := range []func(context.Context, []string, io.Writer) error{ConfigShow, ConfigSources} { for _, command := range []func(context.Context, []string, io.Writer) error{ConfigShow, ConfigSources} {
if err := command(context.Background(), []string{ if err := command(context.Background(), []string{
"--config", pipelinePath, "--campaign-file", campaignPath, "--profile", "testing", "--config", pipelinePath, "--campaign-file", campaignPath, "--overlay", "testing",
}, io.Discard); err != nil { }, io.Discard); err != nil {
t.Fatalf("testing inspection command %T: %v", command, err) t.Fatalf("testing inspection command %T: %v", command, err)
} }
@@ -272,19 +272,19 @@ func TestAssembledSplitBundleCommandsUseOneEffectiveFamilyConfiguration(t *testi
}, &diff); err != nil { }, &diff); err != nil {
t.Fatalf("compare profiles: %v", err) t.Fatalf("compare profiles: %v", err)
} }
if !strings.Contains(diff.String(), "audita.model") || !strings.Contains(diff.String(), "character_items_arannis.profile_id") { if !strings.Contains(diff.String(), "audita.proposal_profile") || !strings.Contains(diff.String(), "character_items_arannis.profile_id") {
t.Fatalf("profile diff = %q, want model and expanded family changes", diff.String()) t.Fatalf("profile diff = %q, want proposal profile and expanded family changes", diff.String())
} }
common := []string{ common := []string{
"2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath,
"--session", sessionPath, "--profile", "testing", "--session", sessionPath, "--overlay", "testing",
} }
var planned bytes.Buffer var planned bytes.Buffer
if err := Plan(context.Background(), common, &planned); err != nil { if err := Plan(context.Background(), common, &planned); err != nil {
t.Fatalf("plan testing bundle: %v", err) t.Fatalf("plan testing bundle: %v", err)
} }
if !strings.Contains(planned.String(), "profile=testing") { if !strings.Contains(planned.String(), "overlay=testing") {
t.Fatalf("plan output = %q, want testing provenance", planned.String()) t.Fatalf("plan output = %q, want testing provenance", planned.String())
} }
@@ -305,7 +305,7 @@ func TestAssembledSplitBundleCommandsUseOneEffectiveFamilyConfiguration(t *testi
if !reflect.DeepEqual(capturedPlan.Names(), []string{"analyze"}) { if !reflect.DeepEqual(capturedPlan.Names(), []string{"analyze"}) {
t.Fatalf("bounded plan = %#v, want analyze only", capturedPlan.Names()) t.Fatalf("bounded plan = %#v, want analyze only", capturedPlan.Names())
} }
if profile, ok := config.SelectedPipelineProfile(capturedCfg.Pipeline); !ok || profile.Name != "testing" { if profile, ok := config.SelectedPipelineOverlay(capturedCfg.Pipeline); !ok || profile.Name != "testing" {
t.Fatalf("captured profile = %#v, selected=%t", profile, ok) t.Fatalf("captured profile = %#v, selected=%t", profile, ok)
} }
if digest := config.EffectivePipelineDigest(capturedCfg.Pipeline); digest == "" || !strings.Contains(runOut.String(), "digest="+digest) { if digest := config.EffectivePipelineDigest(capturedCfg.Pipeline); digest == "" || !strings.Contains(runOut.String(), "digest="+digest) {
@@ -391,7 +391,7 @@ func loadAssembledSplitBundleConfig(t *testing.T, profile string) *config.Config
pipelinePath, campaignPath, sessionPath := assembledSplitBundlePaths() pipelinePath, campaignPath, sessionPath := assembledSplitBundlePaths()
options := config.SessionLoadOptions{} options := config.SessionLoadOptions{}
if profile != "" { if profile != "" {
options.Profile = &profile options.Overlay = &profile
} }
cfg, err := config.LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, options) cfg, err := config.LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, options)
if err != nil { if err != nil {
@@ -415,8 +415,8 @@ func assertAssembledProvenance(t *testing.T, store *manifest.LocalStore, summary
t.Fatal(err) t.Fatal(err)
} }
value := session.EffectiveConfig value := session.EffectiveConfig
profileMatches := value != nil && ((profile == "" && value.SelectedProfile == nil) || profileMatches := value != nil && ((profile == "" && value.SelectedOverlay == nil) ||
(profile != "" && value.SelectedProfile != nil && value.SelectedProfile.Name == profile)) (profile != "" && value.SelectedOverlay != nil && value.SelectedOverlay.Name == profile))
if !profileMatches || value.EffectiveConfigDigest != digest { if !profileMatches || value.EffectiveConfigDigest != digest {
t.Fatalf("effective configuration provenance = %#v, want profile=%q digest=%q", value, profile, digest) t.Fatalf("effective configuration provenance = %#v, want profile=%q digest=%q", value, profile, digest)
} }

View File

@@ -57,7 +57,7 @@ func TestBoundedRunParsingRejectsDuplicateSingletons(t *testing.T) {
{name: "through mixed", args: []string{"session", "--through", "analyze", "--through=publish"}, want: "--through may be specified only once"}, {name: "through mixed", args: []string{"session", "--through", "analyze", "--through=publish"}, want: "--through may be specified only once"},
{name: "force separate", args: []string{"session", "--force", "--force"}, want: "--force may be specified only once"}, {name: "force separate", args: []string{"session", "--force", "--force"}, want: "--force may be specified only once"},
{name: "force equals", args: []string{"session", "--force=true", "--force=false"}, want: "--force may be specified only once"}, {name: "force equals", args: []string{"session", "--force=true", "--force=false"}, want: "--force may be specified only once"},
{name: "profile", args: []string{"session", "--profile", "production", "--profile=testing"}, want: "--profile may be specified only once"}, {name: "overlay", args: []string{"session", "--overlay", "production", "--overlay=testing"}, want: "--overlay may be specified only once"},
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
@@ -69,29 +69,29 @@ func TestBoundedRunParsingRejectsDuplicateSingletons(t *testing.T) {
} }
} }
func TestBoundedRunParsingRetainsExplicitProfilePresence(t *testing.T) { func TestBoundedRunParsingRetainsExplicitOverlayPresence(t *testing.T) {
withoutProfile, err := parseBoundedRunRequest("run", []string{"session"}, io.Discard) withoutOverlay, err := parseBoundedRunRequest("run", []string{"session"}, io.Discard)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if got := withoutProfile.Config.sessionOptions().Profile; got != nil { if got := withoutOverlay.Config.sessionOptions().Overlay; got != nil {
t.Fatalf("omitted profile = %#v, want nil", got) t.Fatalf("omitted overlay = %#v, want nil", got)
} }
withProfile, err := parseBoundedRunRequest("run", []string{"session", "--profile", "testing"}, io.Discard) withOverlay, err := parseBoundedRunRequest("run", []string{"session", "--overlay", "testing"}, io.Discard)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if got := withProfile.Config.sessionOptions().Profile; got == nil || *got != "testing" { if got := withOverlay.Config.sessionOptions().Overlay; got == nil || *got != "testing" {
t.Fatalf("explicit profile = %#v, want testing", got) t.Fatalf("explicit overlay = %#v, want testing", got)
} }
explicitEmpty, err := parseBoundedRunRequest("run", []string{"session", "--profile", ""}, io.Discard) explicitEmpty, err := parseBoundedRunRequest("run", []string{"session", "--overlay", ""}, io.Discard)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if got := explicitEmpty.Config.sessionOptions().Profile; got == nil || *got != "" { if got := explicitEmpty.Config.sessionOptions().Overlay; got == nil || *got != "" {
t.Fatalf("explicit empty profile = %#v, want non-nil empty", got) t.Fatalf("explicit empty overlay = %#v, want non-nil empty", got)
} }
} }

View File

@@ -93,7 +93,7 @@ func cleanAllLocalWithDependencies(flags commonConfigFlags, dryRun, clearCache b
strings.TrimSpace(flags.previousSessionID) != "" { strings.TrimSpace(flags.previousSessionID) != "" {
return fmt.Errorf("clean: --all cannot be combined with --campaign, --campaign-file, --session, a session_id, or --previous-session-id") return fmt.Errorf("clean: --all cannot be combined with --campaign, --campaign-file, --session, a session_id, or --previous-session-id")
} }
_, pipelineCfg, err := loadPipelineConfigWithDependencies(flags.pipelinePath, config.PipelineLoadOptions{Profile: flags.profile.pointer()}, flags.secretsDir.pointer(), deps) _, pipelineCfg, err := loadPipelineConfigWithDependencies(flags.pipelinePath, config.PipelineLoadOptions{Overlay: flags.overlay.pointer()}, flags.secretsDir.pointer(), deps)
if err != nil { if err != nil {
return fmt.Errorf("clean: %w", err) return fmt.Errorf("clean: %w", err)
} }

View File

@@ -229,7 +229,7 @@ seriatim:
binary: ` + seriatimBinary + ` binary: ` + seriatimBinary + `
audita: audita:
binary: ` + auditaBinary + ` binary: ` + auditaBinary + `
llm_api_key: OPENROUTER_API_KEY credentials: [OPENROUTER_API_KEY]
notification: notification:
mode: noop mode: noop
` `
@@ -274,6 +274,28 @@ inputs:
if !strings.Contains(stdout.String(), "stage=polish executed=1 skipped=0") { if !strings.Contains(stdout.String(), "stage=polish executed=1 skipped=0") {
t.Fatalf("stdout = %q, want polish execution", stdout.String()) t.Fatalf("stdout = %q, want polish execution", stdout.String())
} }
recorded, err := (&manifest.LocalStore{}).Load(context.Background(), filepath.Join(workRoot, "manifest.json"))
if err != nil {
t.Fatalf("load polished manifest: %v", err)
}
polish := recorded.Stages["polish"]
if polish == nil || len(polish.Outputs) != 1 || polish.Outputs[0].Kind != "transcript_polished" {
t.Fatalf("polish outputs = %#v, want only canonical transcript", polish)
}
if len(polish.Logs) != 5 || len(polish.GeneratedConfigs) != 1 {
t.Fatalf("polish diagnostics = %#v, want logs, reports, and invocation", polish)
}
for _, name := range []string{"errors.yml", "recoveries.yml", "report.md"} {
found := false
for _, path := range polish.Logs {
if filepath.Base(path) == name {
found = true
}
}
if !found {
t.Fatalf("report %q absent from manifest diagnostics: %#v", name, polish.Logs)
}
}
foundReference := false foundReference := false
if err := filepath.WalkDir(workRoot, func(path string, entry os.DirEntry, walkErr error) error { if err := filepath.WalkDir(workRoot, func(path string, entry os.DirEntry, walkErr error) error {
if walkErr != nil || entry.IsDir() { if walkErr != nil || entry.IsDir() {
@@ -778,10 +800,18 @@ func TestAuditaAppHelper(t *testing.T) {
os.Exit(2) os.Exit(2)
} }
processArgs := args[start:] processArgs := args[start:]
if len(processArgs) < 2 || processArgs[0] != "process" {
_, _ = os.Stderr.WriteString("expected Audita v2 process invocation\n")
os.Exit(2)
}
for _, arg := range processArgs {
if arg == "--report-json" || arg == "--work-dir" || arg == "--debug" || arg == "--reporting=false" {
_, _ = os.Stderr.WriteString("retired or unwanted Audita flag\n")
os.Exit(2)
}
}
outputPath := appSeriatimFlagValue(processArgs, "--output") outputPath := appSeriatimFlagValue(processArgs, "--output")
reportPath := appSeriatimFlagValue(processArgs, "--report-json")
workDir := appSeriatimFlagValue(processArgs, "--work-dir")
if strings.TrimSpace(outputPath) == "" { if strings.TrimSpace(outputPath) == "" {
_, _ = os.Stderr.WriteString("missing --output\n") _, _ = os.Stderr.WriteString("missing --output\n")
os.Exit(2) os.Exit(2)
@@ -794,19 +824,9 @@ func TestAuditaAppHelper(t *testing.T) {
_, _ = os.Stderr.WriteString(fmt.Sprintf("write output: %v\n", err)) _, _ = os.Stderr.WriteString(fmt.Sprintf("write output: %v\n", err))
os.Exit(2) os.Exit(2)
} }
if strings.TrimSpace(reportPath) != "" { for _, name := range []string{"errors.yml", "recoveries.yml", "report.md"} {
if err := os.MkdirAll(filepath.Dir(reportPath), 0o755); err != nil { if err := os.WriteFile(filepath.Join(filepath.Dir(outputPath), name), []byte("status: completed\n"), 0o644); err != nil {
_, _ = os.Stderr.WriteString(fmt.Sprintf("mkdir report dir: %v\n", err)) _, _ = os.Stderr.WriteString(fmt.Sprintf("write %s: %v\n", name, err))
os.Exit(2)
}
if err := os.WriteFile(reportPath, []byte(`{"report":true}`), 0o644); err != nil {
_, _ = os.Stderr.WriteString(fmt.Sprintf("write report: %v\n", err))
os.Exit(2)
}
}
if strings.TrimSpace(workDir) != "" {
if err := os.MkdirAll(workDir, 0o755); err != nil {
_, _ = os.Stderr.WriteString(fmt.Sprintf("mkdir work dir: %v\n", err))
os.Exit(2) os.Exit(2)
} }
} }

View File

@@ -80,22 +80,22 @@ func TestConfigArtifactsReportsGeneratedFamilyProvenance(t *testing.T) {
} }
} }
func TestConfigArtifactsReportsProfiledFamilyContributors(t *testing.T) { func TestConfigArtifactsReportsOverlayFamilyContributors(t *testing.T) {
pipelinePath, campaignPath := writeInspectionFamilyConfig(t) pipelinePath, campaignPath := writeInspectionFamilyConfig(t)
profilePath := filepath.Join(filepath.Dir(pipelinePath), "profiles", "testing.yml") overlayPath := filepath.Join(filepath.Dir(pipelinePath), "overlays", "testing.yml")
mustWriteTestFile(t, profilePath, `scriptorium: mustWriteTestFile(t, overlayPath, `scriptorium:
artifact_families: artifact_families:
character_note: character_note:
prompt_id: dnd.character_note.testing prompt_id: dnd.character_note.testing
`) `)
args := []string{"--config", pipelinePath, "--campaign-file", campaignPath, "--profile", "testing"} args := []string{"--config", pipelinePath, "--campaign-file", campaignPath, "--overlay", "testing"}
var catalog bytes.Buffer var catalog bytes.Buffer
if err := ConfigArtifacts(context.Background(), args, &catalog); err != nil { if err := ConfigArtifacts(context.Background(), args, &catalog); err != nil {
t.Fatal(err) t.Fatal(err)
} }
records := catalogRecordsByKey(t, catalog.String()) records := catalogRecordsByKey(t, catalog.String())
if got := strings.Split(records["character_note_arannis"][2], ","); !reflect.DeepEqual(got, []string{pipelinePath, profilePath}) { if got := strings.Split(records["character_note_arannis"][2], ","); !reflect.DeepEqual(got, []string{overlayPath, pipelinePath}) {
t.Fatalf("generated family definitions = %#v", got) t.Fatalf("generated family definitions = %#v", got)
} }
@@ -103,16 +103,16 @@ func TestConfigArtifactsReportsProfiledFamilyContributors(t *testing.T) {
if err := ConfigSources(context.Background(), args, &sources); err != nil { if err := ConfigSources(context.Background(), args, &sources); err != nil {
t.Fatal(err) t.Fatal(err)
} }
want := "scriptorium.artifacts.character_note_arannis.prompt_id\tfamily\t" + profilePath want := "scriptorium.artifacts.character_note_arannis.prompt_id\tfamily\t" + overlayPath
if !strings.Contains(sources.String(), want) { if !strings.Contains(sources.String(), want) {
t.Fatalf("sources output missing profiled family contributor %q:\n%s", want, sources.String()) t.Fatalf("sources output missing overlay family contributor %q:\n%s", want, sources.String())
} }
} }
func TestConfigArtifactsReportsBaseAndProfileContributors(t *testing.T) { func TestConfigArtifactsReportsBaseAndOverlayContributors(t *testing.T) {
dir := t.TempDir() dir := t.TempDir()
pipelinePath := filepath.Join(dir, "pipeline.yml") pipelinePath := filepath.Join(dir, "pipeline.yml")
profilePath := filepath.Join(dir, "profiles", "testing.yml") overlayPath := filepath.Join(dir, "overlays", "testing.yml")
mustWriteTestFile(t, pipelinePath, `workspace: mustWriteTestFile(t, pipelinePath, `workspace:
root: /srv/narratio root: /srv/narratio
whisperx: whisperx:
@@ -124,26 +124,26 @@ scriptorium:
enabled: false enabled: false
output_path: artifacts/notes.md output_path: artifacts/notes.md
`) `)
mustWriteTestFile(t, profilePath, `scriptorium: mustWriteTestFile(t, overlayPath, `scriptorium:
artifacts: artifacts:
notes: notes:
enabled: true enabled: true
prompt_id: notes prompt_id: notes
profile_only: overlay_only:
enabled: false enabled: false
output_path: artifacts/profile-only.md output_path: artifacts/overlay-only.md
`) `)
var out bytes.Buffer var out bytes.Buffer
if err := ConfigArtifacts(context.Background(), []string{"--config", pipelinePath, "--profile", "testing"}, &out); err != nil { if err := ConfigArtifacts(context.Background(), []string{"--config", pipelinePath, "--overlay", "testing"}, &out); err != nil {
t.Fatal(err) t.Fatal(err)
} }
records := catalogRecordsByKey(t, out.String()) records := catalogRecordsByKey(t, out.String())
if got := strings.Split(records["notes"][2], ","); !reflect.DeepEqual(got, []string{pipelinePath, profilePath}) { if got := strings.Split(records["notes"][2], ","); !reflect.DeepEqual(got, []string{overlayPath, pipelinePath}) {
t.Fatalf("notes definitions = %#v", got) t.Fatalf("notes definitions = %#v", got)
} }
if got := records["profile_only"][2]; got != profilePath { if got := records["overlay_only"][2]; got != overlayPath {
t.Fatalf("profile-only definition = %q, want %q", got, profilePath) t.Fatalf("overlay-only definition = %q, want %q", got, overlayPath)
} }
} }

View File

@@ -17,7 +17,7 @@ type inspectionFlags struct {
pipelinePath string pipelinePath string
campaignPath string campaignPath string
campaignFilePath string campaignFilePath string
profile singletonStringFlag overlay singletonStringFlag
secretsDir singletonStringFlag secretsDir singletonStringFlag
} }
@@ -77,8 +77,8 @@ func configValidateWithDependencies(_ context.Context, args []string, out io.Wri
if err != nil { if err != nil {
return fmt.Errorf("config validate: %w", err) return fmt.Errorf("config validate: %w", err)
} }
_, err = fmt.Fprintf(out, "Configuration valid: root=%s; profile=%s; digest=%s\n", _, err = fmt.Fprintf(out, "Configuration valid: root=%s; overlay=%s; digest=%s\n",
inspectionRootPath(resolved), inspectionProfile(resolved.Pipeline), config.EffectivePipelineDigest(resolved.Pipeline)) inspectionRootPath(resolved), inspectionOverlay(resolved.Pipeline), config.EffectivePipelineDigest(resolved.Pipeline))
return err return err
} }
@@ -214,12 +214,12 @@ func parseInspectionFlags(command string, args []string, out io.Writer) (inspect
fs.StringVar(&flags.pipelinePath, "config", "", "path to pipeline.yml (optional; defaults searched)") fs.StringVar(&flags.pipelinePath, "config", "", "path to pipeline.yml (optional; defaults searched)")
fs.StringVar(&flags.campaignPath, "campaign", "", "campaign ID") fs.StringVar(&flags.campaignPath, "campaign", "", "campaign ID")
fs.StringVar(&flags.campaignFilePath, "campaign-file", "", "path to campaign.yml") fs.StringVar(&flags.campaignFilePath, "campaign-file", "", "path to campaign.yml")
flags.profile.name = "profile" flags.overlay.name = "overlay"
fs.Var(&flags.profile, "profile", "named pipeline profile") fs.Var(&flags.overlay, "overlay", "named pipeline overlay")
flags.secretsDir.name = "secrets-dir" flags.secretsDir.name = "secrets-dir"
fs.Var(&flags.secretsDir, "secrets-dir", "secrets directory (optional; defaults beside pipeline.yml)") fs.Var(&flags.secretsDir, "secrets-dir", "secrets directory (optional; defaults beside pipeline.yml)")
fs.Usage = func() { fs.Usage = func() {
fmt.Fprintf(out, "Usage: narratio %s [--config <pipeline.yml>] [--campaign <id> | --campaign-file <campaign.yml>] [--profile <name>] [--secrets-dir <path>]\n\n", command) fmt.Fprintf(out, "Usage: narratio %s [--config <pipeline.yml>] [--campaign <id> | --campaign-file <campaign.yml>] [--overlay <name>] [--secrets-dir <path>]\n\n", command)
fmt.Fprintln(out, "Resolves configuration without a session, workspace, manifest, adapters, or external services.") fmt.Fprintln(out, "Resolves configuration without a session, workspace, manifest, adapters, or external services.")
fmt.Fprintln(out) fmt.Fprintln(out)
fmt.Fprintln(out, "Flags:") fmt.Fprintln(out, "Flags:")
@@ -238,7 +238,7 @@ func parseInspectionFlags(command string, args []string, out io.Writer) (inspect
} }
func resolveInspectionConfigWithDependencies(flags inspectionFlags, deps commandDependencies) (*inspectionConfig, error) { func resolveInspectionConfigWithDependencies(flags inspectionFlags, deps commandDependencies) (*inspectionConfig, error) {
pipelinePath, pipeline, err := loadPipelineConfigWithDependencies(flags.pipelinePath, config.PipelineLoadOptions{Profile: flags.profile.pointer()}, flags.secretsDir.pointer(), deps) pipelinePath, pipeline, err := loadPipelineConfigWithDependencies(flags.pipelinePath, config.PipelineLoadOptions{Overlay: flags.overlay.pointer()}, flags.secretsDir.pointer(), deps)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -315,9 +315,9 @@ func inspectionRootPath(resolved *inspectionConfig) string {
return resolved.PipelinePath return resolved.PipelinePath
} }
func inspectionProfile(pipeline *config.PipelineConfig) string { func inspectionOverlay(pipeline *config.PipelineConfig) string {
if profile, ok := config.SelectedPipelineProfile(pipeline); ok { if overlay, ok := config.SelectedPipelineOverlay(pipeline); ok {
return profile.Name return overlay.Name
} }
return "none" return "none"
} }
@@ -325,7 +325,7 @@ func inspectionProfile(pipeline *config.PipelineConfig) string {
func writeConfigCommandUsage(out io.Writer) { func writeConfigCommandUsage(out io.Writer) {
fmt.Fprintln(out, "Usage: narratio config <validate|show|sources|artifacts|diff>") fmt.Fprintln(out, "Usage: narratio config <validate|show|sources|artifacts|diff>")
fmt.Fprintln(out) fmt.Fprintln(out)
fmt.Fprintln(out, "Use config validate to check an effective pipeline, config show to print normalized YAML, config sources to report ownership, config artifacts to list concrete artifacts, or config diff to compare two profiles.") fmt.Fprintln(out, "Use config validate to check an effective pipeline, config show to print normalized YAML, config sources to report ownership, config artifacts to list concrete artifacts, or config diff to compare two overlays.")
} }
func writeInspectionSourceHeader(out io.Writer, resolved *inspectionConfig) error { func writeInspectionSourceHeader(out io.Writer, resolved *inspectionConfig) error {
@@ -343,11 +343,11 @@ func writeInspectionSourceHeader(out io.Writer, resolved *inspectionConfig) erro
return err return err
} }
} }
if profile, ok := config.SelectedPipelineProfile(resolved.Pipeline); ok { if overlay, ok := config.SelectedPipelineOverlay(resolved.Pipeline); ok {
if _, err := fmt.Fprintf(out, "profile: name=%s selection=%s overlay=%s\n", profile.Name, profile.Source, config.NormalizedConfigurationPath(profile.OverlayPath)); err != nil { if _, err := fmt.Fprintf(out, "overlay: name=%s selection=%s path=%s\n", overlay.Name, overlay.Source, config.NormalizedConfigurationPath(overlay.OverlayPath)); err != nil {
return err return err
} }
} else if _, err := fmt.Fprintln(out, "profile: none"); err != nil { } else if _, err := fmt.Fprintln(out, "overlay: none"); err != nil {
return err return err
} }
if resolved.Campaign == nil { if resolved.Campaign == nil {

View File

@@ -34,6 +34,7 @@ func TestConfigCommandHelpAndDispatch(t *testing.T) {
{name: "stage flag", args: []string{"config", "show", "--from", "prepare"}, want: "flag provided but not defined", code: 1}, {name: "stage flag", args: []string{"config", "show", "--from", "prepare"}, want: "flag provided but not defined", code: 1},
{name: "force flag", args: []string{"config", "show", "--force"}, want: "flag provided but not defined", code: 1}, {name: "force flag", args: []string{"config", "show", "--force"}, want: "flag provided but not defined", code: 1},
{name: "artifact flag", args: []string{"config", "show", "--artifacts", "recap"}, want: "flag provided but not defined", code: 1}, {name: "artifact flag", args: []string{"config", "show", "--artifacts", "recap"}, want: "flag provided but not defined", code: 1},
{name: "retired selector", args: []string{"config", "validate", "--profile", "testing"}, want: "flag provided but not defined", code: 1},
} { } {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
var stdout, stderr bytes.Buffer var stdout, stderr bytes.Buffer
@@ -102,7 +103,7 @@ whisperx:
if err := ConfigValidate(context.Background(), []string{"--config", pipelinePath}, &validateOut); err != nil { if err := ConfigValidate(context.Background(), []string{"--config", pipelinePath}, &validateOut); err != nil {
t.Fatalf("ConfigValidate() error = %v", err) t.Fatalf("ConfigValidate() error = %v", err)
} }
if !strings.Contains(validateOut.String(), "Configuration valid: root=") || !strings.Contains(validateOut.String(), "; profile=none; digest=") { if !strings.Contains(validateOut.String(), "Configuration valid: root=") || !strings.Contains(validateOut.String(), "; overlay=none; digest=") {
t.Fatalf("validate output = %q", validateOut.String()) t.Fatalf("validate output = %q", validateOut.String())
} }
@@ -127,7 +128,7 @@ whisperx:
if strings.Contains(sourcesOut.String(), secret) { if strings.Contains(sourcesOut.String(), secret) {
t.Fatalf("sources output leaked a raw secret: %q", sourcesOut.String()) t.Fatalf("sources output leaked a raw secret: %q", sourcesOut.String())
} }
writeInspectionProfiles(t, pipelinePath, "whisperx:\n language: en\n", "whisperx:\n language: fr\n") writeInspectionOverlays(t, pipelinePath, "whisperx:\n language: en\n", "whisperx:\n language: fr\n")
var diffOut bytes.Buffer var diffOut bytes.Buffer
if err := ConfigDiff(context.Background(), []string{"production", "testing", "--config", pipelinePath}, &diffOut); err != nil { if err := ConfigDiff(context.Background(), []string{"production", "testing", "--config", pipelinePath}, &diffOut); err != nil {
t.Fatalf("ConfigDiff() error = %v", err) t.Fatalf("ConfigDiff() error = %v", err)
@@ -143,10 +144,10 @@ whisperx:
} }
} }
func TestConfigDiffReportsSemanticProfileChanges(t *testing.T) { func TestConfigDiffReportsSemanticOverlayChanges(t *testing.T) {
workspaceRoot := t.TempDir() workspaceRoot := t.TempDir()
pipelinePath, _, _ := writeValidConfigFiles(t, workspaceRoot) pipelinePath, _, _ := writeValidConfigFiles(t, workspaceRoot)
writeInspectionProfiles(t, pipelinePath, `workspace: writeInspectionOverlays(t, pipelinePath, `workspace:
cleanup_after_publish: true cleanup_after_publish: true
publish: publish:
upload_run: true upload_run: true
@@ -203,7 +204,7 @@ scriptorium:
t.Fatalf("reversed ConfigDiff() error = %v", err) t.Fatalf("reversed ConfigDiff() error = %v", err)
} }
if !strings.Contains(reversed.String(), "changed\twhisperx.language\t\"fr\"\t\"en\"\n") { if !strings.Contains(reversed.String(), "changed\twhisperx.language\t\"fr\"\t\"en\"\n") {
t.Fatalf("reversed diff did not independently resolve profiles:\n%s", reversed.String()) t.Fatalf("reversed diff did not independently resolve overlays:\n%s", reversed.String())
} }
} }
@@ -219,7 +220,7 @@ audita:
scriptorium: scriptorium:
artifacts: null artifacts: null
`) `)
mustWriteTestFile(t, filepath.Join(dir, "profiles", "empty.yml"), `audita: mustWriteTestFile(t, filepath.Join(dir, "overlays", "empty.yml"), `audita:
modules: [] modules: []
scriptorium: scriptorium:
artifacts: {} artifacts: {}
@@ -229,7 +230,7 @@ scriptorium:
if err := ConfigShow(context.Background(), []string{"--config", pipelinePath}, &base); err != nil { if err := ConfigShow(context.Background(), []string{"--config", pipelinePath}, &base); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err := ConfigShow(context.Background(), []string{"--config", pipelinePath, "--profile", "empty"}, &empty); err != nil { if err := ConfigShow(context.Background(), []string{"--config", pipelinePath, "--overlay", "empty"}, &empty); err != nil {
t.Fatal(err) t.Fatal(err)
} }
for _, want := range []string{"modules: null\n", "artifacts: null\n"} { for _, want := range []string{"modules: null\n", "artifacts: null\n"} {
@@ -239,7 +240,7 @@ scriptorium:
} }
for _, want := range []string{"modules: []\n", "artifacts: {}\n"} { for _, want := range []string{"modules: []\n", "artifacts: {}\n"} {
if !strings.Contains(empty.String(), want) { if !strings.Contains(empty.String(), want) {
t.Fatalf("empty-profile show output missing %q:\n%s", want, empty.String()) t.Fatalf("empty-overlay show output missing %q:\n%s", want, empty.String())
} }
} }
@@ -259,7 +260,7 @@ scriptorium:
func TestConfigDiffComparesExpandedFamiliesAndPublishRules(t *testing.T) { func TestConfigDiffComparesExpandedFamiliesAndPublishRules(t *testing.T) {
pipelinePath, campaignPath := writeInspectionFamilyConfig(t) pipelinePath, campaignPath := writeInspectionFamilyConfig(t)
writeInspectionProfiles(t, pipelinePath, `scriptorium: writeInspectionOverlays(t, pipelinePath, `scriptorium:
artifact_families: artifact_families:
character_note: character_note:
enabled: false enabled: false
@@ -301,11 +302,11 @@ func TestConfigDiffComparesExpandedFamiliesAndPublishRules(t *testing.T) {
func TestConfigDiffReportsEqualityAndRejectsInvalidInput(t *testing.T) { func TestConfigDiffReportsEqualityAndRejectsInvalidInput(t *testing.T) {
workspaceRoot := t.TempDir() workspaceRoot := t.TempDir()
pipelinePath, campaignPath, _ := writeValidConfigFiles(t, workspaceRoot) pipelinePath, campaignPath, _ := writeValidConfigFiles(t, workspaceRoot)
writeInspectionProfiles(t, pipelinePath, "whisperx:\n language: en\n", "whisperx:\n language: en\n") writeInspectionOverlays(t, pipelinePath, "whisperx:\n language: en\n", "whisperx:\n language: en\n")
var equal bytes.Buffer var equal bytes.Buffer
if err := ConfigDiff(context.Background(), []string{"production", "testing", "--config", pipelinePath}, &equal); err != nil { if err := ConfigDiff(context.Background(), []string{"production", "testing", "--config", pipelinePath}, &equal); err != nil {
t.Fatalf("ConfigDiff() equal profiles error = %v", err) t.Fatalf("ConfigDiff() equal overlays error = %v", err)
} }
if got := equal.String(); got != "no differences\n" { if got := equal.String(); got != "no differences\n" {
t.Fatalf("equal diff output = %q", got) t.Fatalf("equal diff output = %q", got)
@@ -316,7 +317,7 @@ func TestConfigDiffReportsEqualityAndRejectsInvalidInput(t *testing.T) {
{"production", "--config", pipelinePath}, {"production", "--config", pipelinePath},
{"production", "production", "--config", pipelinePath}, {"production", "production", "--config", pipelinePath},
{"unknown", "testing", "--config", pipelinePath}, {"unknown", "testing", "--config", pipelinePath},
{"production", "testing", "--config", pipelinePath, "--profile", "production"}, {"production", "testing", "--config", pipelinePath, "--overlay", "production"},
{"production", "testing", "--config", pipelinePath, "--config", pipelinePath}, {"production", "testing", "--config", pipelinePath, "--config", pipelinePath},
{"production", "testing", "--config", pipelinePath, "--campaign", "sample-campaign", "--campaign-file", campaignPath}, {"production", "testing", "--config", pipelinePath, "--campaign", "sample-campaign", "--campaign-file", campaignPath},
} { } {
@@ -326,10 +327,10 @@ func TestConfigDiffReportsEqualityAndRejectsInvalidInput(t *testing.T) {
} }
} }
func TestConfigDiffBootstrapsSecretsOnceForBothProfiles(t *testing.T) { func TestConfigDiffBootstrapsSecretsOnceForBothOverlays(t *testing.T) {
workspaceRoot := t.TempDir() workspaceRoot := t.TempDir()
pipelinePath, _, _ := writeValidConfigFiles(t, workspaceRoot) pipelinePath, _, _ := writeValidConfigFiles(t, workspaceRoot)
writeInspectionProfiles(t, pipelinePath, "whisperx:\n language: en\n", "whisperx:\n language: fr\n") writeInspectionOverlays(t, pipelinePath, "whisperx:\n language: en\n", "whisperx:\n language: fr\n")
secretsDir := t.TempDir() secretsDir := t.TempDir()
const secretName = "NARRATIO_DIFF_BOOTSTRAP_REPORT" const secretName = "NARRATIO_DIFF_BOOTSTRAP_REPORT"
restoreEnvAfterTest(t, secretName) restoreEnvAfterTest(t, secretName)
@@ -388,32 +389,32 @@ func TestConfigInspectionOutputsNeverExposeResolvedCredentialValues(t *testing.T
`, 1) `, 1)
pipelineYAML += `notarius: pipelineYAML += `notarius:
enabled: false enabled: false
llm_api_key: NARRATIO_INSPECT_NOTARIUS_ONE credentials: [NARRATIO_INSPECT_NOTARIUS_ONE]
` `
if err := os.WriteFile(pipelinePath, []byte(pipelineYAML), 0o644); err != nil { if err := os.WriteFile(pipelinePath, []byte(pipelineYAML), 0o644); err != nil {
t.Fatal(err) t.Fatal(err)
} }
writeInspectionProfiles(t, pipelinePath, writeInspectionOverlays(t, pipelinePath,
"audita:\n model: production\n llm_api_key: NARRATIO_INSPECT_LLM_ONE\n", "audita:\n proposal_profile: production\n credentials: [NARRATIO_INSPECT_LLM_ONE]\n",
"audita:\n model: testing\n llm_api_key: NARRATIO_INSPECT_LLM_TWO\nnotarius:\n llm_api_key: NARRATIO_INSPECT_NOTARIUS_TWO\n", "audita:\n proposal_profile: testing\n credentials: [NARRATIO_INSPECT_LLM_TWO]\nnotarius:\n credentials: [NARRATIO_INSPECT_NOTARIUS_TWO]\n",
) )
mustWriteTestFile(t, filepath.Join(filepath.Dir(pipelinePath), "profiles", "without-notarius-key.yml"), "notarius:\n llm_api_key: null\n") mustWriteTestFile(t, filepath.Join(filepath.Dir(pipelinePath), "overlays", "without-notarius-key.yml"), "notarius:\n credentials: []\n")
var validate bytes.Buffer var validate bytes.Buffer
if err := ConfigValidate(context.Background(), []string{"--config", pipelinePath, "--profile", "production"}, &validate); err != nil { if err := ConfigValidate(context.Background(), []string{"--config", pipelinePath, "--overlay", "production"}, &validate); err != nil {
t.Fatalf("config validate: %v", err) t.Fatalf("config validate: %v", err)
} }
var show bytes.Buffer var show bytes.Buffer
if err := ConfigShow(context.Background(), []string{"--config", pipelinePath, "--profile", "production"}, &show); err != nil { if err := ConfigShow(context.Background(), []string{"--config", pipelinePath, "--overlay", "production"}, &show); err != nil {
t.Fatalf("config show: %v", err) t.Fatalf("config show: %v", err)
} }
var sources bytes.Buffer var sources bytes.Buffer
if err := ConfigSources(context.Background(), []string{"--config", pipelinePath, "--profile", "production"}, &sources); err != nil { if err := ConfigSources(context.Background(), []string{"--config", pipelinePath, "--overlay", "production"}, &sources); err != nil {
t.Fatalf("config sources: %v", err) t.Fatalf("config sources: %v", err)
} }
var catalog bytes.Buffer var catalog bytes.Buffer
if err := ConfigArtifacts(context.Background(), []string{"--config", pipelinePath, "--profile", "production"}, &catalog); err != nil { if err := ConfigArtifacts(context.Background(), []string{"--config", pipelinePath, "--overlay", "production"}, &catalog); err != nil {
t.Fatalf("config artifacts: %v", err) t.Fatalf("config artifacts: %v", err)
} }
var diff bytes.Buffer var diff bytes.Buffer
@@ -421,7 +422,7 @@ func TestConfigInspectionOutputsNeverExposeResolvedCredentialValues(t *testing.T
t.Fatalf("config diff: %v", err) t.Fatalf("config diff: %v", err)
} }
var removed bytes.Buffer var removed bytes.Buffer
if err := ConfigShow(context.Background(), []string{"--config", pipelinePath, "--profile", "without-notarius-key"}, &removed); err != nil { if err := ConfigShow(context.Background(), []string{"--config", pipelinePath, "--overlay", "without-notarius-key"}, &removed); err != nil {
t.Fatalf("config show with removed Notarius credential: %v", err) t.Fatalf("config show with removed Notarius credential: %v", err)
} }
for label, output := range map[string]string{"show": show.String(), "sources": sources.String(), "artifacts": catalog.String(), "diff": diff.String()} { for label, output := range map[string]string{"show": show.String(), "sources": sources.String(), "artifacts": catalog.String(), "diff": diff.String()} {
@@ -438,11 +439,11 @@ func TestConfigInspectionOutputsNeverExposeResolvedCredentialValues(t *testing.T
!strings.Contains(diff.String(), "NARRATIO_INSPECT_NOTARIUS_ONE") || !strings.Contains(diff.String(), "NARRATIO_INSPECT_NOTARIUS_TWO") { !strings.Contains(diff.String(), "NARRATIO_INSPECT_NOTARIUS_ONE") || !strings.Contains(diff.String(), "NARRATIO_INSPECT_NOTARIUS_TWO") {
t.Fatalf("diff omitted safe credential references: %q", diff.String()) t.Fatalf("diff omitted safe credential references: %q", diff.String())
} }
if !strings.Contains(sources.String(), "notarius.llm_api_key") { if !strings.Contains(sources.String(), "notarius.credentials") {
t.Fatalf("sources omitted Notarius credential ownership: %q", sources.String()) t.Fatalf("sources omitted Notarius credential ownership: %q", sources.String())
} }
if strings.Contains(removed.String(), "llm_api_key") || strings.Contains(removed.String(), "NARRATIO_INSPECT_NOTARIUS_ONE") { if strings.Contains(removed.String(), "NARRATIO_INSPECT_NOTARIUS_ONE") {
t.Fatalf("profile null did not remove Notarius credential: %q", removed.String()) t.Fatalf("empty overlay did not remove Notarius credential: %q", removed.String())
} }
} }
@@ -450,7 +451,7 @@ func TestConfigValidateRejectsUnavailableNotariusCredential(t *testing.T) {
const envName = "NARRATIO_INSPECT_NOTARIUS_MISSING" const envName = "NARRATIO_INSPECT_NOTARIUS_MISSING"
restoreEnvAfterTest(t, envName) restoreEnvAfterTest(t, envName)
path := filepath.Join(t.TempDir(), "pipeline.yml") path := filepath.Join(t.TempDir(), "pipeline.yml")
mustWriteTestFile(t, path, "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n llm_api_key: "+envName+"\n") mustWriteTestFile(t, path, "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n credentials: ["+envName+"]\n")
err := ConfigValidate(context.Background(), []string{"--config", path}, io.Discard) err := ConfigValidate(context.Background(), []string{"--config", path}, io.Discard)
if err == nil || !strings.Contains(err.Error(), "secret.unset") { if err == nil || !strings.Contains(err.Error(), "secret.unset") {
t.Fatalf("ConfigValidate() error = %v, want unavailable credential failure", err) t.Fatalf("ConfigValidate() error = %v, want unavailable credential failure", err)
@@ -475,36 +476,36 @@ func TestConfigCommandsInspectMaintainedSplitBundleWithoutRuntimeState(t *testin
if err := ConfigDiff(context.Background(), []string{"default", "testing", "--config", pipelinePath, "--campaign-file", campaignPath}, &diff); err != nil { if err := ConfigDiff(context.Background(), []string{"default", "testing", "--config", pipelinePath, "--campaign-file", campaignPath}, &diff); err != nil {
t.Fatalf("ConfigDiff() error = %v", err) t.Fatalf("ConfigDiff() error = %v", err)
} }
if !strings.Contains(diff.String(), "audita.model") { if !strings.Contains(diff.String(), "audita.proposal_profile") {
t.Fatalf("split bundle profile diff = %q, want model change", diff.String()) t.Fatalf("split bundle overlay diff = %q, want proposal profile change", diff.String())
} }
if _, err := os.Stat(workspacePath); !os.IsNotExist(err) { if _, err := os.Stat(workspacePath); !os.IsNotExist(err) {
t.Fatalf("inspection created example workspace: %v", err) t.Fatalf("inspection created example workspace: %v", err)
} }
} }
func writeInspectionProfiles(t *testing.T, pipelinePath, production, testing string) { func writeInspectionOverlays(t *testing.T, pipelinePath, production, testing string) {
t.Helper() t.Helper()
profilesDir := filepath.Join(filepath.Dir(pipelinePath), "profiles") overlaysDir := filepath.Join(filepath.Dir(pipelinePath), "overlays")
mustWriteTestFile(t, filepath.Join(profilesDir, "production.yml"), production) mustWriteTestFile(t, filepath.Join(overlaysDir, "production.yml"), production)
mustWriteTestFile(t, filepath.Join(profilesDir, "testing.yml"), testing) mustWriteTestFile(t, filepath.Join(overlaysDir, "testing.yml"), testing)
} }
func TestConfigCommandsSelectProfilesAndCampaigns(t *testing.T) { func TestConfigCommandsSelectOverlaysAndCampaigns(t *testing.T) {
workspaceRoot := t.TempDir() workspaceRoot := t.TempDir()
pipelinePath, campaignPath, _ := writeValidConfigFiles(t, workspaceRoot) pipelinePath, campaignPath, _ := writeValidConfigFiles(t, workspaceRoot)
enableCommandTestProfiles(t, pipelinePath) enableCommandTestOverlays(t, pipelinePath)
var defaultOut bytes.Buffer var defaultOut bytes.Buffer
if err := ConfigValidate(context.Background(), []string{"--config", pipelinePath}, &defaultOut); err != nil { if err := ConfigValidate(context.Background(), []string{"--config", pipelinePath}, &defaultOut); err != nil {
t.Fatalf("default ConfigValidate() error = %v", err) t.Fatalf("default ConfigValidate() error = %v", err)
} }
if !strings.Contains(defaultOut.String(), "profile=none") { if !strings.Contains(defaultOut.String(), "overlay=none") {
t.Fatalf("default output = %q", defaultOut.String()) t.Fatalf("default output = %q", defaultOut.String())
} }
var explicitOut bytes.Buffer var explicitOut bytes.Buffer
if err := ConfigShow(context.Background(), []string{"--config", pipelinePath, "--profile", "testing"}, &explicitOut); err != nil { if err := ConfigShow(context.Background(), []string{"--config", pipelinePath, "--overlay", "testing"}, &explicitOut); err != nil {
t.Fatalf("explicit ConfigShow() error = %v", err) t.Fatalf("explicit ConfigShow() error = %v", err)
} }
if !strings.Contains(explicitOut.String(), "language: fr") { if !strings.Contains(explicitOut.String(), "language: fr") {
@@ -589,9 +590,9 @@ whisperx:
func TestConfigSourcesReportsStableOwnership(t *testing.T) { func TestConfigSourcesReportsStableOwnership(t *testing.T) {
workspaceRoot := t.TempDir() workspaceRoot := t.TempDir()
pipelinePath, campaignPath, _ := writeValidConfigFiles(t, workspaceRoot) pipelinePath, campaignPath, _ := writeValidConfigFiles(t, workspaceRoot)
enableCommandTestProfiles(t, pipelinePath) enableCommandTestOverlays(t, pipelinePath)
args := []string{"--config", pipelinePath, "--campaign-file", campaignPath, "--profile", "testing"} args := []string{"--config", pipelinePath, "--campaign-file", campaignPath, "--overlay", "testing"}
var first, second bytes.Buffer var first, second bytes.Buffer
if err := ConfigSources(context.Background(), args, &first); err != nil { if err := ConfigSources(context.Background(), args, &first); err != nil {
t.Fatalf("first ConfigSources() error = %v", err) t.Fatalf("first ConfigSources() error = %v", err)
@@ -606,13 +607,13 @@ func TestConfigSourcesReportsStableOwnership(t *testing.T) {
for _, want := range []string{ for _, want := range []string{
"root: ", "root: ",
"imports: none", "imports: none",
"profile: name=testing selection=explicit overlay=", "overlay: name=testing selection=explicit path=",
"campaign: id=sample-campaign source=", "campaign: id=sample-campaign source=",
"party: source=", "party: source=",
"digest: ", "digest: ",
"path\trole\tsource\n", "path\trole\tsource\n",
"workspace.root\troot\t", "workspace.root\troot\t",
"whisperx.language\tprofile\t", "whisperx.language\toverlay\t",
"derived.players\tparty\t", "derived.players\tparty\t",
"trim.enabled\tdefault\tdefault", "trim.enabled\tdefault\tdefault",
} { } {
@@ -647,10 +648,10 @@ func TestConfigSourcesReportsCanonicalFamilyAndPublishOrigins(t *testing.T) {
} }
} }
func TestConfigSourcesPreservesProfileOwnershipThroughFamilyExpansion(t *testing.T) { func TestConfigSourcesPreservesOverlayOwnershipThroughFamilyExpansion(t *testing.T) {
pipelinePath, campaignPath := writeInspectionFamilyConfig(t) pipelinePath, campaignPath := writeInspectionFamilyConfig(t)
profilePath := filepath.Join(filepath.Dir(pipelinePath), "profiles", "testing.yml") overlayPath := filepath.Join(filepath.Dir(pipelinePath), "overlays", "testing.yml")
mustWriteTestFile(t, profilePath, `scriptorium: mustWriteTestFile(t, overlayPath, `scriptorium:
artifact_families: artifact_families:
character_note: character_note:
enabled: true enabled: true
@@ -658,12 +659,12 @@ func TestConfigSourcesPreservesProfileOwnershipThroughFamilyExpansion(t *testing
`) `)
var out bytes.Buffer var out bytes.Buffer
if err := ConfigSources(context.Background(), []string{"--config", pipelinePath, "--campaign-file", campaignPath, "--profile", "testing"}, &out); err != nil { if err := ConfigSources(context.Background(), []string{"--config", pipelinePath, "--campaign-file", campaignPath, "--overlay", "testing"}, &out); err != nil {
t.Fatalf("ConfigSources() error = %v", err) t.Fatalf("ConfigSources() error = %v", err)
} }
want := "scriptorium.artifacts.character_note_arannis.enabled\tfamily\t" + profilePath want := "scriptorium.artifacts.character_note_arannis.enabled\tfamily\t" + overlayPath
if !strings.Contains(out.String(), want) { if !strings.Contains(out.String(), want) {
t.Fatalf("sources output missing profile-generated ownership %q:\n%s", want, out.String()) t.Fatalf("sources output missing overlay-generated ownership %q:\n%s", want, out.String())
} }
} }
@@ -671,7 +672,7 @@ func TestConfigSourcesAttributesInferredArtifactDependencies(t *testing.T) {
dir := t.TempDir() dir := t.TempDir()
pipelinePath := filepath.Join(dir, "pipeline.yml") pipelinePath := filepath.Join(dir, "pipeline.yml")
inputPath := filepath.Join(dir, "input-only.yml") inputPath := filepath.Join(dir, "input-only.yml")
profilePath := filepath.Join(dir, "profiles", "testing.yml") overlayPath := filepath.Join(dir, "overlays", "testing.yml")
mustWriteTestFile(t, pipelinePath, `configkit: mustWriteTestFile(t, pipelinePath, `configkit:
imports: imports:
- path: input-only.yml - path: input-only.yml
@@ -701,7 +702,7 @@ scriptorium:
prior: prior:
source: narratio.artifact.first source: narratio.artifact.first
`) `)
mustWriteTestFile(t, profilePath, `scriptorium: mustWriteTestFile(t, overlayPath, `scriptorium:
artifacts: artifacts:
mixed: mixed:
inputs: inputs:
@@ -710,13 +711,13 @@ scriptorium:
`) `)
var out bytes.Buffer var out bytes.Buffer
if err := ConfigSources(context.Background(), []string{"--config", pipelinePath, "--profile", "testing"}, &out); err != nil { if err := ConfigSources(context.Background(), []string{"--config", pipelinePath, "--overlay", "testing"}, &out); err != nil {
t.Fatal(err) t.Fatal(err)
} }
for _, want := range []string{ for _, want := range []string{
"scriptorium.artifacts.input_only.depends_on\timport\t" + inputPath, "scriptorium.artifacts.input_only.depends_on\timport\t" + inputPath,
"scriptorium.artifacts.mixed.depends_on\troot\t" + pipelinePath, "scriptorium.artifacts.mixed.depends_on\troot\t" + pipelinePath,
"scriptorium.artifacts.mixed.depends_on\tprofile\t" + profilePath, "scriptorium.artifacts.mixed.depends_on\toverlay\t" + overlayPath,
} { } {
if !strings.Contains(out.String(), want) { if !strings.Contains(out.String(), want) {
t.Fatalf("sources output missing dependency contributor %q:\n%s", want, out.String()) t.Fatalf("sources output missing dependency contributor %q:\n%s", want, out.String())
@@ -727,11 +728,11 @@ scriptorium:
} }
} }
func TestConfigSourcesReportsRootImportProfileAndDefaultOwnership(t *testing.T) { func TestConfigSourcesReportsRootImportOverlayAndDefaultOwnership(t *testing.T) {
dir := t.TempDir() dir := t.TempDir()
rootPath := filepath.Join(dir, "pipeline.yml") rootPath := filepath.Join(dir, "pipeline.yml")
importPath := filepath.Join(dir, "base.yml") importPath := filepath.Join(dir, "base.yml")
profilePath := filepath.Join(dir, "profiles", "testing.yml") overlayPath := filepath.Join(dir, "overlays", "testing.yml")
mustWriteTestFile(t, rootPath, `configkit: mustWriteTestFile(t, rootPath, `configkit:
imports: imports:
- path: base.yml - path: base.yml
@@ -741,19 +742,19 @@ whisperx:
transcribe_url: https://transcription.example.com/transcribe transcribe_url: https://transcription.example.com/transcribe
`) `)
mustWriteTestFile(t, importPath, "storage:\n backend: local\n") mustWriteTestFile(t, importPath, "storage:\n backend: local\n")
mustWriteTestFile(t, profilePath, "whisperx:\n language: fr\n") mustWriteTestFile(t, overlayPath, "whisperx:\n language: fr\n")
var out bytes.Buffer var out bytes.Buffer
if err := ConfigSources(context.Background(), []string{"--config", rootPath, "--profile", "testing"}, &out); err != nil { if err := ConfigSources(context.Background(), []string{"--config", rootPath, "--overlay", "testing"}, &out); err != nil {
t.Fatalf("ConfigSources() error = %v", err) t.Fatalf("ConfigSources() error = %v", err)
} }
output := out.String() output := out.String()
for _, want := range []string{ for _, want := range []string{
"import: " + importPath, "import: " + importPath,
"profile: name=testing selection=explicit overlay=" + profilePath, "overlay: name=testing selection=explicit path=" + overlayPath,
"workspace.root\troot\t" + rootPath, "workspace.root\troot\t" + rootPath,
"storage.backend\timport\t" + importPath, "storage.backend\timport\t" + importPath,
"whisperx.language\tprofile\t" + profilePath, "whisperx.language\toverlay\t" + overlayPath,
"trim.enabled\tdefault\tdefault", "trim.enabled\tdefault\tdefault",
} { } {
if !strings.Contains(output, want) { if !strings.Contains(output, want) {

View File

@@ -20,8 +20,8 @@ type configDiffFlags struct {
} }
type configDiffRequest struct { type configDiffRequest struct {
leftProfile string leftOverlay string
rightProfile string rightOverlay string
flags configDiffFlags flags configDiffFlags
} }
@@ -37,7 +37,7 @@ type configDiffRecord struct {
Right string Right string
} }
// ConfigDiff compares two explicitly selected profiles through the same // ConfigDiff compares two explicitly selected overlays through the same
// read-only configuration resolution boundary used by config validate, show, // read-only configuration resolution boundary used by config validate, show,
// and sources. Differences describe normalized effective values rather than // and sources. Differences describe normalized effective values rather than
// the layout of root, import, or overlay files. // the layout of root, import, or overlay files.
@@ -100,7 +100,7 @@ func configDiffWithDependencies(_ context.Context, args []string, out io.Writer,
} }
func parseConfigDiffRequest(args []string, out io.Writer) (configDiffRequest, error) { func parseConfigDiffRequest(args []string, out io.Writer) (configDiffRequest, error) {
profiles, flagArgs := splitConfigDiffArguments(args) overlays, flagArgs := splitConfigDiffArguments(args)
fs := flag.NewFlagSet("config diff", flag.ContinueOnError) fs := flag.NewFlagSet("config diff", flag.ContinueOnError)
fs.SetOutput(out) fs.SetOutput(out)
var request configDiffRequest var request configDiffRequest
@@ -113,9 +113,9 @@ func parseConfigDiffRequest(args []string, out io.Writer) (configDiffRequest, er
fs.Var(&request.flags.campaignFilePath, "campaign-file", "path to campaign.yml") fs.Var(&request.flags.campaignFilePath, "campaign-file", "path to campaign.yml")
fs.Var(&request.flags.secretsDir, "secrets-dir", "secrets directory (optional; defaults beside pipeline.yml)") fs.Var(&request.flags.secretsDir, "secrets-dir", "secrets directory (optional; defaults beside pipeline.yml)")
fs.Usage = func() { fs.Usage = func() {
fmt.Fprintln(out, "Usage: narratio config diff <left-profile> <right-profile> [--config <pipeline.yml>] [--campaign <id> | --campaign-file <campaign.yml>] [--secrets-dir <path>]") fmt.Fprintln(out, "Usage: narratio config diff <left-overlay> <right-overlay> [--config <pipeline.yml>] [--campaign <id> | --campaign-file <campaign.yml>] [--secrets-dir <path>]")
fmt.Fprintln(out) fmt.Fprintln(out)
fmt.Fprintln(out, "Compares fully resolved profiles without a session, workspace, manifest, adapters, or external services.") fmt.Fprintln(out, "Compares fully resolved overlays without a session, workspace, manifest, adapters, or external services.")
fmt.Fprintln(out) fmt.Fprintln(out)
fmt.Fprintln(out, "Flags:") fmt.Fprintln(out, "Flags:")
fs.PrintDefaults() fs.PrintDefaults()
@@ -123,30 +123,30 @@ func parseConfigDiffRequest(args []string, out io.Writer) (configDiffRequest, er
if err := fs.Parse(flagArgs); err != nil { if err := fs.Parse(flagArgs); err != nil {
return configDiffRequest{}, fmt.Errorf("config diff: invalid flags: %w", err) return configDiffRequest{}, fmt.Errorf("config diff: invalid flags: %w", err)
} }
profiles = append(profiles, fs.Args()...) overlays = append(overlays, fs.Args()...)
if len(profiles) != 2 || strings.TrimSpace(profiles[0]) == "" || strings.TrimSpace(profiles[1]) == "" { if len(overlays) != 2 || strings.TrimSpace(overlays[0]) == "" || strings.TrimSpace(overlays[1]) == "" {
return configDiffRequest{}, fmt.Errorf("config diff: exactly two non-empty profile names are required") return configDiffRequest{}, fmt.Errorf("config diff: exactly two non-empty overlay names are required")
} }
if profiles[0] == profiles[1] { if overlays[0] == overlays[1] {
return configDiffRequest{}, fmt.Errorf("config diff: profile names must differ") return configDiffRequest{}, fmt.Errorf("config diff: overlay names must differ")
} }
if request.flags.campaignPath.set && request.flags.campaignFilePath.set { if request.flags.campaignPath.set && request.flags.campaignFilePath.set {
return configDiffRequest{}, fmt.Errorf("config diff: --campaign and --campaign-file are mutually exclusive") return configDiffRequest{}, fmt.Errorf("config diff: --campaign and --campaign-file are mutually exclusive")
} }
request.leftProfile = profiles[0] request.leftOverlay = overlays[0]
request.rightProfile = profiles[1] request.rightOverlay = overlays[1]
return request, nil return request, nil
} }
// splitConfigDiffArguments accepts the documented positional-first syntax and // splitConfigDiffArguments accepts the documented positional-first syntax and
// also permits flags before or between profile names. Values belonging to the // also permits flags before or between overlay names. Values belonging to the
// supported string flags stay with their flag so they are not mistaken for // supported string flags stay with their flag so they are not mistaken for
// profile names. // overlay names.
func splitConfigDiffArguments(args []string) (profiles, flagArgs []string) { func splitConfigDiffArguments(args []string) (overlays, flagArgs []string) {
for index := 0; index < len(args); index++ { for index := 0; index < len(args); index++ {
argument := args[index] argument := args[index]
if !strings.HasPrefix(argument, "-") || argument == "-" { if !strings.HasPrefix(argument, "-") || argument == "-" {
profiles = append(profiles, argument) overlays = append(overlays, argument)
continue continue
} }
flagArgs = append(flagArgs, argument) flagArgs = append(flagArgs, argument)
@@ -161,12 +161,12 @@ func splitConfigDiffArguments(args []string) (profiles, flagArgs []string) {
index++ index++
flagArgs = append(flagArgs, args[index]) flagArgs = append(flagArgs, args[index])
} }
return profiles, flagArgs return overlays, flagArgs
} }
func configDiffStringFlag(name string) bool { func configDiffStringFlag(name string) bool {
switch name { switch name {
case "config", "campaign", "campaign-file", "profile", "secrets-dir": case "config", "campaign", "campaign-file", "secrets-dir":
return true return true
default: default:
return false return false
@@ -175,13 +175,13 @@ func configDiffStringFlag(name string) bool {
func resolveConfigDiff(request configDiffRequest, deps commandDependencies) (*configDiffResolved, error) { func resolveConfigDiff(request configDiffRequest, deps commandDependencies) (*configDiffResolved, error) {
deps = normalizeCommandDependencies(deps) deps = normalizeCommandDependencies(deps)
pipelinePath, leftPipeline, err := loadPipelineConfigWithDependencies(request.flags.pipelinePath.value, config.PipelineLoadOptions{Profile: &request.leftProfile}, request.flags.secretsDir.pointer(), deps) pipelinePath, leftPipeline, err := loadPipelineConfigWithDependencies(request.flags.pipelinePath.value, config.PipelineLoadOptions{Overlay: &request.leftOverlay}, request.flags.secretsDir.pointer(), deps)
if err != nil { if err != nil {
return nil, fmt.Errorf("load left pipeline profile: %w", err) return nil, fmt.Errorf("load left pipeline overlay: %w", err)
} }
_, rightPipeline, err := loadPipelineConfigWithDependencies(request.flags.pipelinePath.value, config.PipelineLoadOptions{Profile: &request.rightProfile}, request.flags.secretsDir.pointer(), deps) _, rightPipeline, err := loadPipelineConfigWithDependencies(request.flags.pipelinePath.value, config.PipelineLoadOptions{Overlay: &request.rightOverlay}, request.flags.secretsDir.pointer(), deps)
if err != nil { if err != nil {
return nil, fmt.Errorf("load right pipeline profile: %w", err) return nil, fmt.Errorf("load right pipeline overlay: %w", err)
} }
needsCampaign := pipelineHasArtifactFamilies(leftPipeline) || pipelineHasArtifactFamilies(rightPipeline) needsCampaign := pipelineHasArtifactFamilies(leftPipeline) || pipelineHasArtifactFamilies(rightPipeline)
hasCampaignSelection := request.flags.campaignPath.set || request.flags.campaignFilePath.set hasCampaignSelection := request.flags.campaignPath.set || request.flags.campaignFilePath.set
@@ -259,7 +259,7 @@ func resolveSharedDiffCampaignPath(left, right *config.PipelineConfig, flags con
return "", rightErr return "", rightErr
} }
if leftPath != rightPath { if leftPath != rightPath {
return "", fmt.Errorf("profile selections resolve different campaign files; specify --campaign-file to compare one campaign") return "", fmt.Errorf("overlay selections resolve different campaign files; specify --campaign-file to compare one campaign")
} }
return leftPath, nil return leftPath, nil
} }

View File

@@ -46,7 +46,7 @@ func loadCommandConfigWithDependencies(ctx context.Context, pipelineFlag, campai
} }
}() }()
base, err := loadPipelineCampaignConfigWithDependencies(pipelineFlag, campaignFlag, campaignFileFlag, config.PipelineLoadOptions{Profile: sessionOpts.Profile}, secretsDir, deps) base, err := loadPipelineCampaignConfigWithDependencies(pipelineFlag, campaignFlag, campaignFileFlag, config.PipelineLoadOptions{Overlay: sessionOpts.Overlay}, secretsDir, deps)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -14,13 +14,13 @@ func effectiveConfigProvenance(cfg *config.Config) *manifest.EffectiveConfigProv
provenance := &manifest.EffectiveConfigProvenance{ provenance := &manifest.EffectiveConfigProvenance{
EffectiveConfigDigest: config.EffectivePipelineDigest(cfg.Pipeline), EffectiveConfigDigest: config.EffectivePipelineDigest(cfg.Pipeline),
} }
if selected, ok := config.SelectedPipelineProfile(cfg.Pipeline); ok { if selected, ok := config.SelectedPipelineOverlay(cfg.Pipeline); ok {
provenance.SelectedProfile = &manifest.SelectedProfileProvenance{ provenance.SelectedOverlay = &manifest.SelectedOverlayProvenance{
Name: selected.Name, Name: selected.Name,
Source: selected.Source, Source: selected.Source,
} }
} }
if provenance.SelectedProfile == nil && provenance.EffectiveConfigDigest == "" { if provenance.SelectedOverlay == nil && provenance.EffectiveConfigDigest == "" {
return nil return nil
} }
return provenance return provenance
@@ -35,30 +35,30 @@ func applyEffectiveConfigProvenance(m *manifest.Manifest, cfg *config.Config) {
func effectiveConfigSummary(cfg *config.Config) string { func effectiveConfigSummary(cfg *config.Config) string {
provenance := effectiveConfigProvenance(cfg) provenance := effectiveConfigProvenance(cfg)
if provenance == nil { if provenance == nil {
return "profile=none digest=unavailable" return "overlay=none digest=unavailable"
} }
profile := "none" overlay := "none"
if provenance.SelectedProfile != nil { if provenance.SelectedOverlay != nil {
profile = provenance.SelectedProfile.Name + " (" + provenance.SelectedProfile.Source + ")" overlay = provenance.SelectedOverlay.Name + " (" + provenance.SelectedOverlay.Source + ")"
} }
digest := provenance.EffectiveConfigDigest digest := provenance.EffectiveConfigDigest
if digest == "" { if digest == "" {
digest = "unavailable" digest = "unavailable"
} }
return fmt.Sprintf("profile=%s digest=%s", profile, digest) return fmt.Sprintf("overlay=%s digest=%s", overlay, digest)
} }
func persistedEffectiveConfigSummary(provenance *manifest.EffectiveConfigProvenance) string { func persistedEffectiveConfigSummary(provenance *manifest.EffectiveConfigProvenance) string {
if provenance == nil { if provenance == nil {
return "profile=none digest=unavailable" return "overlay=none digest=unavailable"
} }
profile := "none" overlay := "none"
if provenance.SelectedProfile != nil { if provenance.SelectedOverlay != nil {
profile = provenance.SelectedProfile.Name + " (" + provenance.SelectedProfile.Source + ")" overlay = provenance.SelectedOverlay.Name + " (" + provenance.SelectedOverlay.Source + ")"
} }
digest := provenance.EffectiveConfigDigest digest := provenance.EffectiveConfigDigest
if digest == "" { if digest == "" {
digest = "unavailable" digest = "unavailable"
} }
return fmt.Sprintf("profile=%s digest=%s", profile, digest) return fmt.Sprintf("overlay=%s digest=%s", overlay, digest)
} }

View File

@@ -665,16 +665,16 @@ func TestExtractLifecycleCredentialChangesRemainResumable(t *testing.T) {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
cfg, env, runner := extractionLifecycleFixture(t, true) cfg, env, runner := extractionLifecycleFixture(t, true)
if test.before != nil { if test.before != nil {
cfg.Pipeline.Notarius.LLMAPIKey = test.before(t) cfg.Pipeline.Notarius.Credentials = []configkit.Secret{*test.before(t)}
} }
analyzeRuns := 0 analyzeRuns := 0
plan := extractionLifecyclePlan(t, &analyzeRuns) plan := extractionLifecyclePlan(t, &analyzeRuns)
if _, err := executeStages(context.Background(), cfg, plan, RunOptions{Env: env}); err != nil { if _, err := executeStages(context.Background(), cfg, plan, RunOptions{Env: env}); err != nil {
t.Fatalf("initial executeStages() error = %v", err) t.Fatalf("initial executeStages() error = %v", err)
} }
cfg.Pipeline.Notarius.LLMAPIKey = nil cfg.Pipeline.Notarius.Credentials = nil
if test.after != nil { if test.after != nil {
cfg.Pipeline.Notarius.LLMAPIKey = test.after(t) cfg.Pipeline.Notarius.Credentials = []configkit.Secret{*test.after(t)}
} }
resumed, err := executeStages(context.Background(), cfg, plan, RunOptions{Env: env}) resumed, err := executeStages(context.Background(), cfg, plan, RunOptions{Env: env})
if err != nil { if err != nil {
@@ -817,7 +817,7 @@ func TestExtractLifecycleRealConfigProfilesSelectNotariusExplicitly(t *testing.T
if err := os.WriteFile(filepath.Join(filepath.Dir(pipelinePath), "notarius.yml"), []byte("pipelines: {}\n"), 0o644); err != nil { if err := os.WriteFile(filepath.Join(filepath.Dir(pipelinePath), "notarius.yml"), []byte("pipelines: {}\n"), 0o644); err != nil {
t.Fatal(err) t.Fatal(err)
} }
profilesDir := filepath.Join(filepath.Dir(pipelinePath), "profiles") profilesDir := filepath.Join(filepath.Dir(pipelinePath), "overlays")
if err := os.MkdirAll(profilesDir, 0o755); err != nil { if err := os.MkdirAll(profilesDir, 0o755); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -832,7 +832,7 @@ func TestExtractLifecycleRealConfigProfilesSelectNotariusExplicitly(t *testing.T
} }
load := func(profile string) *config.Config { load := func(profile string) *config.Config {
t.Helper() t.Helper()
loaded, err := config.LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, config.SessionLoadOptions{Profile: &profile}) loaded, err := config.LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath, config.SessionLoadOptions{Overlay: &profile})
if err != nil { if err != nil {
t.Fatalf("load profile %q: %v", profile, err) t.Fatalf("load profile %q: %v", profile, err)
} }
@@ -876,7 +876,7 @@ func TestPreparedPipelineAndManifestExcludeNotariusCredentialValue(t *testing.T)
const name = "NARRATIO_LIFECYCLE_PERSISTED_KEY" const name = "NARRATIO_LIFECYCLE_PERSISTED_KEY"
const canary = "notarius-persisted-credential-canary" const canary = "notarius-persisted-credential-canary"
cfg, env, _ := extractionLifecycleFixture(t, true) cfg, env, _ := extractionLifecycleFixture(t, true)
cfg.Pipeline.Notarius.LLMAPIKey = loadLifecycleNotariusCredential(t, name, canary) cfg.Pipeline.Notarius.Credentials = []configkit.Secret{*loadLifecycleNotariusCredential(t, name, canary)}
if _, err := executeStages(context.Background(), cfg, prepareExtractLifecyclePlan(t), RunOptions{Env: env}); err != nil { if _, err := executeStages(context.Background(), cfg, prepareExtractLifecyclePlan(t), RunOptions{Env: env}); err != nil {
t.Fatalf("executeStages() error = %v", err) t.Fatalf("executeStages() error = %v", err)
} }
@@ -1181,12 +1181,12 @@ func loadLifecycleNotariusCredential(t *testing.T, name, value string) *configki
t.Helper() t.Helper()
t.Setenv(name, value) t.Setenv(name, value)
path := filepath.Join(t.TempDir(), "pipeline.yml") path := filepath.Join(t.TempDir(), "pipeline.yml")
if err := os.WriteFile(path, []byte("whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n llm_api_key: "+name+"\n"), 0o644); err != nil { if err := os.WriteFile(path, []byte("whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n credentials: ["+name+"]\n"), 0o644); err != nil {
t.Fatal(err) t.Fatal(err)
} }
pipeline, err := config.LoadPipeline(path) pipeline, err := config.LoadPipeline(path)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
return pipeline.Notarius.LLMAPIKey return &pipeline.Notarius.Credentials[0]
} }

View File

@@ -23,7 +23,7 @@ type commonConfigFlags struct {
sessionPath string sessionPath string
sessionID string sessionID string
previousSessionID string previousSessionID string
profile singletonStringFlag overlay singletonStringFlag
secretsDir singletonStringFlag secretsDir singletonStringFlag
} }
@@ -34,8 +34,8 @@ func addCommonConfigFlags(fs *flag.FlagSet, flags *commonConfigFlags) {
fs.StringVar(&flags.sessionPath, "session", "", "path to session.yml") fs.StringVar(&flags.sessionPath, "session", "", "path to session.yml")
fs.StringVar(&flags.sessionID, "session-id", "", "session identifier") fs.StringVar(&flags.sessionID, "session-id", "", "session identifier")
fs.StringVar(&flags.previousSessionID, "previous-session-id", "", "expected previous session identifier") fs.StringVar(&flags.previousSessionID, "previous-session-id", "", "expected previous session identifier")
flags.profile.name = "profile" flags.overlay.name = "overlay"
fs.Var(&flags.profile, "profile", "named pipeline profile") fs.Var(&flags.overlay, "overlay", "named pipeline overlay")
flags.secretsDir.name = "secrets-dir" flags.secretsDir.name = "secrets-dir"
fs.Var(&flags.secretsDir, "secrets-dir", "secrets directory (optional; defaults beside pipeline.yml)") fs.Var(&flags.secretsDir, "secrets-dir", "secrets directory (optional; defaults beside pipeline.yml)")
} }
@@ -44,7 +44,7 @@ func (f commonConfigFlags) sessionOptions() config.SessionLoadOptions {
return config.SessionLoadOptions{ return config.SessionLoadOptions{
SessionID: f.sessionID, SessionID: f.sessionID,
PreviousSessionID: f.previousSessionID, PreviousSessionID: f.previousSessionID,
Profile: f.profile.pointer(), Overlay: f.overlay.pointer(),
} }
} }

View File

@@ -27,7 +27,7 @@ func sessionInitWithDependencies(ctx context.Context, args []string, out io.Writ
fs := flag.NewFlagSet("session init", flag.ContinueOnError) fs := flag.NewFlagSet("session init", flag.ContinueOnError)
fs.SetOutput(io.Discard) fs.SetOutput(io.Discard)
var pipelinePath, campaignPath, campaignFilePath, sessionID, previousSessionID, date, title, output, audioS3Prefix, audioDir string var pipelinePath, campaignPath, campaignFilePath, sessionID, previousSessionID, date, title, output, audioS3Prefix, audioDir string
var profile singletonStringFlag var overlay singletonStringFlag
var secretsDir singletonStringFlag var secretsDir singletonStringFlag
var remote, force bool var remote, force bool
fs.StringVar(&pipelinePath, "config", "", "path to pipeline.yml (optional; defaults searched)") fs.StringVar(&pipelinePath, "config", "", "path to pipeline.yml (optional; defaults searched)")
@@ -40,8 +40,8 @@ func sessionInitWithDependencies(ctx context.Context, args []string, out io.Writ
fs.StringVar(&output, "output", "", "local output session.yml path") fs.StringVar(&output, "output", "", "local output session.yml path")
fs.StringVar(&audioS3Prefix, "audio-s3-prefix", "", "session audio S3 prefix") fs.StringVar(&audioS3Prefix, "audio-s3-prefix", "", "session audio S3 prefix")
fs.StringVar(&audioDir, "audio-dir", "", "local audio directory") fs.StringVar(&audioDir, "audio-dir", "", "local audio directory")
profile.name = "profile" overlay.name = "overlay"
fs.Var(&profile, "profile", "named pipeline profile") fs.Var(&overlay, "overlay", "named pipeline overlay")
secretsDir.name = "secrets-dir" secretsDir.name = "secrets-dir"
fs.Var(&secretsDir, "secrets-dir", "secrets directory (optional; defaults beside pipeline.yml)") fs.Var(&secretsDir, "secrets-dir", "secrets directory (optional; defaults beside pipeline.yml)")
fs.BoolVar(&remote, "remote", false, "write session.yml to S3 session prefix") fs.BoolVar(&remote, "remote", false, "write session.yml to S3 session prefix")
@@ -59,7 +59,7 @@ func sessionInitWithDependencies(ctx context.Context, args []string, out io.Writ
return fmt.Errorf("session init: --audio-dir and --audio-s3-prefix are mutually exclusive") return fmt.Errorf("session init: --audio-dir and --audio-s3-prefix are mutually exclusive")
} }
base, err := loadPipelineCampaignConfigWithDependencies(pipelinePath, campaignPath, campaignFilePath, config.PipelineLoadOptions{Profile: profile.pointer()}, secretsDir.pointer(), deps) base, err := loadPipelineCampaignConfigWithDependencies(pipelinePath, campaignPath, campaignFilePath, config.PipelineLoadOptions{Overlay: overlay.pointer()}, secretsDir.pointer(), deps)
if err != nil { if err != nil {
return fmt.Errorf("session init: %w", err) return fmt.Errorf("session init: %w", err)
} }

View File

@@ -11,10 +11,10 @@ import (
"gitea.maximumdirect.net/eric/narratio/internal/config" "gitea.maximumdirect.net/eric/narratio/internal/config"
) )
func TestRunProfileSelectionFlowsThroughSharedLoader(t *testing.T) { func TestRunOverlaySelectionFlowsThroughSharedLoader(t *testing.T) {
workspaceRoot := t.TempDir() workspaceRoot := t.TempDir()
pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, workspaceRoot) pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, workspaceRoot)
enableCommandTestProfiles(t, pipelinePath) enableCommandTestOverlays(t, pipelinePath)
var language string var language string
executor := func(_ context.Context, cfg *config.Config, _ BoundedPlan, _ RunOptions) (*RunSummary, error) { executor := func(_ context.Context, cfg *config.Config, _ BoundedPlan, _ RunOptions) (*RunSummary, error) {
@@ -23,12 +23,17 @@ func TestRunProfileSelectionFlowsThroughSharedLoader(t *testing.T) {
} }
if err := runWithPipelineExecutor(context.Background(), []string{ if err := runWithPipelineExecutor(context.Background(), []string{
"2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--profile", "testing", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--overlay", "testing",
}, io.Discard, executor); err != nil { }, io.Discard, executor); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if language != "fr" { if language != "fr" {
t.Fatalf("explicit profile language = %q, want fr", language) t.Fatalf("explicit overlay language = %q, want fr", language)
}
if err := runWithPipelineExecutor(context.Background(), []string{
"2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--profile", "testing",
}, io.Discard, executor); err == nil {
t.Fatal("retired pipeline selector was accepted")
} }
if err := runWithPipelineExecutor(context.Background(), []string{ if err := runWithPipelineExecutor(context.Background(), []string{
@@ -40,25 +45,25 @@ func TestRunProfileSelectionFlowsThroughSharedLoader(t *testing.T) {
t.Fatalf("base configuration language = %q, want en", language) t.Fatalf("base configuration language = %q, want en", language)
} }
for _, profile := range []string{"unknown"} { for _, overlay := range []string{"unknown"} {
err := runWithPipelineExecutor(context.Background(), []string{ err := runWithPipelineExecutor(context.Background(), []string{
"2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--profile", profile, "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--overlay", overlay,
}, io.Discard, executor) }, io.Discard, executor)
if err == nil || !strings.Contains(err.Error(), "profile") { if err == nil || !strings.Contains(err.Error(), "overlay") {
t.Fatalf("profile %q error = %v, want selection rejection", profile, err) t.Fatalf("overlay %q error = %v, want selection rejection", overlay, err)
} }
} }
if err := runWithPipelineExecutor(context.Background(), []string{ if err := runWithPipelineExecutor(context.Background(), []string{
"2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--profile", "", "2026-05-03", "--config", pipelinePath, "--campaign-file", campaignPath, "--session", sessionPath, "--overlay", "",
}, io.Discard, executor); err != nil { }, io.Discard, executor); err != nil {
t.Fatalf("explicit empty profile should select base: %v", err) t.Fatalf("explicit empty overlay should select base: %v", err)
} }
} }
func enableCommandTestProfiles(t *testing.T, pipelinePath string) { func enableCommandTestOverlays(t *testing.T, pipelinePath string) {
t.Helper() t.Helper()
dir := filepath.Join(filepath.Dir(pipelinePath), "profiles") dir := filepath.Join(filepath.Dir(pipelinePath), "overlays")
if err := os.MkdirAll(dir, 0o755); err != nil { if err := os.MkdirAll(dir, 0o755); err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@@ -0,0 +1,244 @@
package app
import (
"bytes"
"context"
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
)
const (
sharedProviderName = "NARRATIO_SHARED_PROVIDER_KEY"
auditaOnlyName = "NARRATIO_AUDITA_ONLY_KEY"
sharedProviderKey = "synthetic-shared-provider-value"
auditaOnlyKey = "synthetic-audita-only-value"
)
func TestCommandsShareProviderCredentialAcrossAdapters(t *testing.T) {
configDir := t.TempDir()
workspace := t.TempDir()
secretsDir := filepath.Join(configDir, "secrets")
for name, value := range map[string]string{
sharedProviderName: sharedProviderKey,
auditaOnlyName: auditaOnlyKey,
} {
restoreEnvAfterTest(t, name)
if err := os.Unsetenv(name); err != nil {
t.Fatal(err)
}
mustWriteSecretFile(t, filepath.Join(secretsDir, name), value+"\n")
}
fixture := writeProviderProcessWrapper(t)
seriatim := writeSeriatimAppTestWrapper(t)
configPath := filepath.Join(configDir, "pipeline.yml")
campaignPath := writeAppTestCampaignConfig(t, configDir)
sessionPath := filepath.Join(configDir, "session.yml")
notariusConfig := filepath.Join(configDir, "notarius.yml")
mustWriteTestFile(t, notariusConfig, "pipelines: {}\n")
mustWriteTestFile(t, configPath, `workspace:
root: `+workspace+`
storage:
backend: local
whisperx:
transcribe_url: https://example.com/transcribe
seriatim:
binary: `+seriatim+`
audita:
binary: `+fixture+`
credentials: [`+sharedProviderName+`, `+auditaOnlyName+`]
notarius:
enabled: true
binary: `+fixture+`
config_path: `+notariusConfig+`
pipeline_id: dnd-session
credentials: [`+sharedProviderName+`]
outputs:
npc_registry:
lane_id: npc-registry
media_type: application/json
schema_id: notarius.dnd.npc_registry
schema_version: v1
module_key: dnd/npc-registry
notification:
mode: noop
`)
mustWriteTestFile(t, sessionPath, `session_id: 2026-05-03
campaign: sample-campaign
inputs:
audio_dir: ./audio
speakers_file: ./speakers.yml
autocorrect_file: ./autocorrect.yml
glossary_file: ./glossary.yml
`)
var stdout, stderr bytes.Buffer
if code := Execute([]string{"config", "show", "--config", configPath}, &stdout, &stderr); code != 0 {
t.Fatalf("config show exit = %d; stderr=%q", code, stderr.String())
}
if !strings.Contains(stdout.String(), sharedProviderName) || !strings.Contains(stdout.String(), auditaOnlyName) {
t.Fatalf("config show omitted reference names: %q", stdout.String())
}
assertNoProviderValues(t, stdout.Bytes(), stderr.Bytes())
workRoot := filepath.Join(workspace, "work", "sample-campaign", "2026-05-03")
manifestPath := filepath.Join(workRoot, "manifest.json")
basePath := filepath.Join(workRoot, "transcripts", "base.json")
mustWriteTestFile(t, basePath, `{"schema":"seriatim-intermediate","segments":[]}`)
seedCurrentBuiltInEvidence(t, manifestPath, "2026-05-03", "sample-campaign", "merge", artifacts.TranscriptOutputKindBase, artifacts.ArtifactTranscriptBase, basePath)
mustWriteTestFile(t, filepath.Join(workRoot, "inputs", "glossary.yml"), "[]\n")
args := []string{"--config", configPath, "--campaign-file", campaignPath, "--session", sessionPath}
stdout.Reset()
stderr.Reset()
if code := Execute(append([]string{"run-stage", "polish", "2026-05-03", "--force"}, args...), &stdout, &stderr); code != 0 {
t.Fatalf("polish exit = %d; stderr=%q", code, stderr.String())
}
assertNoProviderValues(t, stdout.Bytes(), stderr.Bytes())
m, err := (&manifest.LocalStore{}).Load(context.Background(), manifestPath)
if err != nil {
t.Fatal(err)
}
if polish := m.Stages["polish"]; polish == nil || len(polish.Outputs) != 1 || len(polish.Logs) != 5 {
t.Fatalf("polish did not retain canonical transcript and ordinary reports: %#v", polish)
}
for _, name := range []string{"errors.yml", "recoveries.yml", "report.md"} {
found := false
for _, path := range m.Stages["polish"].Logs {
found = found || filepath.Base(path) == name
}
if !found {
t.Fatalf("missing polish report %q", name)
}
}
trimmedPath := filepath.Join(workRoot, "transcripts", "final.trimmed.json")
mustWriteTestFile(t, trimmedPath, `{"segments":[]}`)
setCurrentBuiltInEvidence(t, m, "trim", artifacts.TranscriptOutputKindFinalTrimmed, artifacts.ArtifactTranscriptFinalTrimmed, trimmedPath)
if err := (&manifest.LocalStore{}).Save(context.Background(), manifestPath, m); err != nil {
t.Fatal(err)
}
stdout.Reset()
stderr.Reset()
if code := Execute(append([]string{"run-stage", "extract", "2026-05-03", "--force"}, args...), &stdout, &stderr); code != 0 {
t.Fatalf("extract exit = %d; stderr=%q", code, stderr.String())
}
assertNoProviderValues(t, stdout.Bytes(), stderr.Bytes())
if !strings.Contains(stdout.String(), "stage=extract executed=1") {
t.Fatalf("extract did not execute: %q", stdout.String())
}
redactedLogs := 0
if err := filepath.WalkDir(workRoot, func(path string, entry os.DirEntry, walkErr error) error {
if walkErr != nil || entry.IsDir() {
return walkErr
}
data, err := os.ReadFile(path)
if err == nil {
assertNoProviderValues(t, data)
if strings.HasSuffix(path, ".stderr.log") && bytes.Contains(data, []byte("<redacted>")) {
redactedLogs++
}
}
return err
}); err != nil {
t.Fatal(err)
}
if redactedLogs < 2 {
t.Fatalf("redacted subprocess logs = %d, want Audita and Notarius", redactedLogs)
}
}
func assertNoProviderValues(t *testing.T, content ...[]byte) {
t.Helper()
for _, data := range content {
if bytes.Contains(data, []byte(sharedProviderKey)) || bytes.Contains(data, []byte(auditaOnlyKey)) {
t.Fatal("credential value appeared in inspection or workspace output")
}
}
}
func writeProviderProcessWrapper(t *testing.T) string {
t.Helper()
exe, err := os.Executable()
if err != nil {
t.Fatal(err)
}
path := filepath.Join(t.TempDir(), "provider-process.sh")
if err := os.WriteFile(path, []byte("#!/bin/sh\nexec \""+exe+"\" -test.run=TestProviderCredentialProcessFixture -- \"$@\"\n"), 0o755); err != nil {
t.Fatal(err)
}
return path
}
func TestProviderCredentialProcessFixture(t *testing.T) {
if !appHelperInvocation() {
return
}
start := -1
for i, arg := range os.Args {
if arg == "--" {
start = i + 1
break
}
}
if start < 0 || start >= len(os.Args) {
os.Exit(2)
}
args := os.Args[start:]
if os.Getenv(sharedProviderName) != sharedProviderKey {
_, _ = os.Stderr.WriteString("shared credential not forwarded\n")
os.Exit(2)
}
switch args[0] {
case "process":
if os.Getenv(auditaOnlyName) != auditaOnlyKey {
_, _ = os.Stderr.WriteString("Audita-only credential not forwarded\n")
os.Exit(2)
}
output := appSeriatimFlagValue(args, "--output")
if output == "" {
os.Exit(2)
}
if err := os.MkdirAll(filepath.Dir(output), 0o755); err != nil {
os.Exit(2)
}
if err := os.WriteFile(output, []byte(`{"schema":"audita.processed.v1","segments":[]}`), 0o644); err != nil {
os.Exit(2)
}
for _, name := range []string{"errors.yml", "recoveries.yml", "report.md"} {
if err := os.WriteFile(filepath.Join(filepath.Dir(output), name), []byte("status: completed\n"), 0o644); err != nil {
os.Exit(2)
}
}
case "run":
if _, present := os.LookupEnv(auditaOnlyName); present {
_, _ = os.Stderr.WriteString("Audita-only credential reached Notarius\n")
os.Exit(2)
}
root := appSeriatimFlagValue(args, "--output-dir")
bundle := filepath.Join(root, "fixture-run")
if err := os.MkdirAll(filepath.Join(bundle, "lanes"), 0o755); err != nil {
os.Exit(2)
}
for name, value := range map[string]string{
"manifest.json": "{}", "rejected.json": `{"rejected":[]}`,
"warnings.json": `{"schema_version":"notarius.warnings.v2","group_count":0,"occurrence_count":0,"groups":[]}`,
"diagnostics.json": `{"schema_version":"notarius.diagnostics.v1","group_count":0,"occurrence_count":0,"truncated":false,"unrepresented_occurrence_count":0,"groups":[]}`,
"lanes/npc.json": `{"records":[]}`,
"index.json": `{"manifest_file":"manifest.json","output_files":[{"lane_id":"npc-registry","file":"lanes/npc.json","media_type":"application/json","module_key":"dnd/npc-registry","schema_id":"notarius.dnd.npc_registry","schema_version":"v1"}],"rejected_file":"rejected.json","warnings_file":"warnings.json","diagnostics_file":"diagnostics.json"}`,
} {
if err := os.WriteFile(filepath.Join(bundle, filepath.FromSlash(name)), []byte(value), 0o644); err != nil {
os.Exit(2)
}
}
_, _ = os.Stdout.WriteString(fmt.Sprintf(`{"schema_version":"notarius.run-result.v2","run_id":"fixture-run","pipeline_id":"dnd-session","output_directory":%q,"index_file":"index.json","normalized_output_count":1,"rejected_output_count":0,"warning_group_count":0,"warning_occurrence_count":0,"diagnostic_group_count":0,"diagnostic_occurrence_count":0,"diagnostics_truncated":false,"validation_status":"approved"}`, bundle))
default:
os.Exit(2)
}
_, _ = os.Stderr.WriteString(sharedProviderKey + "\n")
os.Exit(0)
}

View File

@@ -14,7 +14,7 @@ import (
func TestRegenerateArtifactsForwardsCanonicalPipelineRequest(t *testing.T) { func TestRegenerateArtifactsForwardsCanonicalPipelineRequest(t *testing.T) {
workspaceRoot := t.TempDir() workspaceRoot := t.TempDir()
pipelinePath, campaignPath, sessionPath := writeValidConfigFilesWithScriptoriumArtifacts(t, workspaceRoot) pipelinePath, campaignPath, sessionPath := writeValidConfigFilesWithScriptoriumArtifacts(t, workspaceRoot)
enableCommandTestProfiles(t, pipelinePath) enableCommandTestOverlays(t, pipelinePath)
var capturedPlan BoundedPlan var capturedPlan BoundedPlan
var capturedOptions RunOptions var capturedOptions RunOptions
executor := func(_ context.Context, cfg *config.Config, plan BoundedPlan, options RunOptions) (*RunSummary, error) { executor := func(_ context.Context, cfg *config.Config, plan BoundedPlan, options RunOptions) (*RunSummary, error) {
@@ -30,7 +30,7 @@ func TestRegenerateArtifactsForwardsCanonicalPipelineRequest(t *testing.T) {
"--config", pipelinePath, "--config", pipelinePath,
"--campaign-file", campaignPath, "--campaign-file", campaignPath,
"--session", sessionPath, "--session", sessionPath,
"--profile", "testing", "--overlay", "testing",
}, io.Discard, io.Discard, executor) }, io.Discard, io.Discard, executor)
if code != 0 { if code != 0 {
t.Fatalf("executeWithPipelineExecutor() code = %d, want 0", code) t.Fatalf("executeWithPipelineExecutor() code = %d, want 0", code)

View File

@@ -44,6 +44,28 @@ func TestCommittedRestorePlanUsesOnlyDeclaredObjects(t *testing.T) {
} }
} }
func TestCommittedRestoreDoesNotRequirePolishRunDiagnostics(t *testing.T) {
cfg := restorePlanConfig(t)
fake := &storage.FakeBackend{}
current := seedCommittedRestoreSnapshot(t, cfg, fake, "20260519T010203Z-a1b2c3d4", map[string][]byte{
"transcripts/full.json": []byte(`{"segments":[]}`),
})
diagnostic := filepath.Join(cfg.Pipeline.Workspace.Root, "runs", current.RunID, "polish", "outputs", "transcripts", "errors.yml")
current.Manifest.Stages["polish"] = &manifest.StageRecord{
Name: "polish", Status: manifest.StatusSucceeded,
Logs: []string{diagnostic},
}
plan, err := buildRestorePlan(context.Background(), cfg, current, fake, RestorePlanOptions{})
if err != nil {
t.Fatalf("buildRestorePlan() error = %v", err)
}
for _, action := range plan.Actions {
if strings.Contains(action.LocalRelativePath, "errors.yml") {
t.Fatalf("diagnostic became a required restore target: %#v", action)
}
}
}
func TestCommittedRestoreDownloadsCarriedOutputFromDeclaredRun(t *testing.T) { func TestCommittedRestoreDownloadsCarriedOutputFromDeclaredRun(t *testing.T) {
cfg := restorePlanConfig(t) cfg := restorePlanConfig(t)
fake := &storage.FakeBackend{} fake := &storage.FakeBackend{}

View File

@@ -80,7 +80,7 @@ func runStageWithDependencies(ctx context.Context, args []string, out io.Writer,
SessionPath: flags.sessionPath, SessionPath: flags.sessionPath,
SessionID: flags.sessionID, SessionID: flags.sessionID,
PreviousSessionID: flags.previousSessionID, PreviousSessionID: flags.previousSessionID,
Profile: flags.profile.pointer(), Overlay: flags.overlay.pointer(),
SecretsDir: flags.secretsDir.pointer(), SecretsDir: flags.secretsDir.pointer(),
Force: force, Force: force,
SelectedArtifacts: normalizedArtifacts, SelectedArtifacts: normalizedArtifacts,
@@ -139,7 +139,7 @@ func analyzeWithDependencies(ctx context.Context, args []string, out io.Writer,
SessionPath: flags.sessionPath, SessionPath: flags.sessionPath,
SessionID: flags.sessionID, SessionID: flags.sessionID,
PreviousSessionID: flags.previousSessionID, PreviousSessionID: flags.previousSessionID,
Profile: flags.profile.pointer(), Overlay: flags.overlay.pointer(),
SecretsDir: flags.secretsDir.pointer(), SecretsDir: flags.secretsDir.pointer(),
Force: true, Force: true,
SelectedArtifacts: normalizedArtifacts, SelectedArtifacts: normalizedArtifacts,
@@ -196,7 +196,7 @@ func publishWithDependencies(ctx context.Context, args []string, out io.Writer,
SessionPath: flags.sessionPath, SessionPath: flags.sessionPath,
SessionID: flags.sessionID, SessionID: flags.sessionID,
PreviousSessionID: flags.previousSessionID, PreviousSessionID: flags.previousSessionID,
Profile: flags.profile.pointer(), Overlay: flags.overlay.pointer(),
SecretsDir: flags.secretsDir.pointer(), SecretsDir: flags.secretsDir.pointer(),
Force: true, Force: true,
SelectedArtifacts: normalizedArtifacts, SelectedArtifacts: normalizedArtifacts,
@@ -224,7 +224,7 @@ type singleStageCommand struct {
SessionPath string SessionPath string
SessionID string SessionID string
PreviousSessionID string PreviousSessionID string
Profile *string Overlay *string
SecretsDir *string SecretsDir *string
Force bool Force bool
SelectedArtifacts []string SelectedArtifacts []string
@@ -240,7 +240,7 @@ func runSingleStageCommand(ctx context.Context, req singleStageCommand, executor
loaded, err := loadCommandConfigWithDependencies(ctx, req.PipelinePath, req.CampaignPath, req.CampaignFilePath, req.SessionPath, config.SessionLoadOptions{ loaded, err := loadCommandConfigWithDependencies(ctx, req.PipelinePath, req.CampaignPath, req.CampaignFilePath, req.SessionPath, config.SessionLoadOptions{
SessionID: req.SessionID, SessionID: req.SessionID,
PreviousSessionID: req.PreviousSessionID, PreviousSessionID: req.PreviousSessionID,
Profile: req.Profile, Overlay: req.Overlay,
}, req.SecretsDir, deps) }, req.SecretsDir, deps)
if err != nil { if err != nil {
return nil, fmt.Errorf("%s: %w", req.CommandName, err) return nil, fmt.Errorf("%s: %w", req.CommandName, err)

View File

@@ -207,35 +207,18 @@ func buildDefaultAuditaRunner(cfg *config.Config) (audita.Runner, error) {
return &audita.NoopRunner{}, nil return &audita.NoopRunner{}, nil
} }
report := false timeout, err := time.ParseDuration(a.Timeout)
if a.Report != nil { if err != nil {
report = *a.Report return nil, fmt.Errorf("parse pipeline.audita.timeout %q: %w", a.Timeout, err)
} }
llmAPIKey := "" runner, err := audita.NewSubprocessRunner(audita.SubprocessRunnerConfig{
llmAPIKeyReference := "" Binary: a.Binary, Timeout: timeout, Credentials: a.Credentials,
if a.LLMAPIKey != nil { Modules: append(a.Modules[:0:0], a.Modules...),
llmAPIKey = a.LLMAPIKey.Value() Overlay: a.Overlay, ProposalProfile: a.ProposalProfile,
llmAPIKeyReference = a.LLMAPIKey.EnvName() ValidationProfile: a.ValidationProfile,
} TranscriptDescription: a.TranscriptDescription, ConfigPath: a.ConfigPath,
OutputSchema: a.OutputSchema,
runner, err := audita.NewSubprocessRunnerFromConfigValues( })
a.Binary,
a.Timeout,
llmAPIKey,
llmAPIKeyReference,
append([]string(nil), a.Modules...),
a.BaseURL,
a.Model,
a.TranscriptDescription,
a.ConfigPath,
a.OutputSchema,
a.WorkDirRetention,
a.TotalLLMConcurrency,
a.ProposalLLMConcurrency,
a.ValidationModel,
a.ValidationLLMConcurrency,
report,
)
if err != nil { if err != nil {
return nil, fmt.Errorf("from pipeline.audita: %w", err) return nil, fmt.Errorf("from pipeline.audita: %w", err)
} }

View File

@@ -138,7 +138,7 @@ func TestNotariusCredentialLoadsFromCommandSecretBootstrap(t *testing.T) {
restoreEnvAfterTest(t, envName) restoreEnvAfterTest(t, envName)
root := t.TempDir() root := t.TempDir()
pipelinePath := filepath.Join(root, "pipeline.yml") pipelinePath := filepath.Join(root, "pipeline.yml")
if err := os.WriteFile(pipelinePath, []byte("whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n llm_api_key: "+envName+"\n"), 0o644); err != nil { if err := os.WriteFile(pipelinePath, []byte("whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n credentials: ["+envName+"]\n"), 0o644); err != nil {
t.Fatal(err) t.Fatal(err)
} }
secretsDir := filepath.Join(root, "secrets") secretsDir := filepath.Join(root, "secrets")
@@ -158,8 +158,8 @@ func TestNotariusCredentialLoadsFromCommandSecretBootstrap(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("load pipeline: %v", err) t.Fatalf("load pipeline: %v", err)
} }
if pipeline.Notarius == nil || pipeline.Notarius.LLMAPIKey == nil || !pipeline.Notarius.LLMAPIKey.IsResolved() || if pipeline.Notarius == nil || len(pipeline.Notarius.Credentials) != 1 || !pipeline.Notarius.Credentials[0].IsResolved() ||
pipeline.Notarius.LLMAPIKey.EnvName() != envName || pipeline.Notarius.LLMAPIKey.Value() != test.wantValue { pipeline.Notarius.Credentials[0].EnvName() != envName || pipeline.Notarius.Credentials[0].Value() != test.wantValue {
t.Fatal("Notarius credential did not resolve from the selected command bootstrap source") t.Fatal("Notarius credential did not resolve from the selected command bootstrap source")
} }
}) })
@@ -220,7 +220,7 @@ func TestExecuteConfigValidateReportsSkippedEmptyBeforeTypedLoadFailure(t *testi
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
pipelineYAML = append(pipelineYAML, []byte("notarius:\n enabled: false\n llm_api_key: "+name+"\n")...) pipelineYAML = append(pipelineYAML, []byte("notarius:\n enabled: false\n credentials: ["+name+"]\n")...)
if err := os.WriteFile(pipelinePath, pipelineYAML, 0o644); err != nil { if err := os.WriteFile(pipelinePath, pipelineYAML, 0o644); err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@@ -5,6 +5,7 @@ import (
"crypto/sha256" "crypto/sha256"
"encoding/hex" "encoding/hex"
"errors" "errors"
"reflect"
"strings" "strings"
"testing" "testing"
"time" "time"
@@ -364,8 +365,8 @@ func TestRefinementSemanticChangesRespectDependencyBranches(t *testing.T) {
wantRuns [7]int wantRuns [7]int
wantExtractStatus manifest.StageStatus wantExtractStatus manifest.StageStatus
}{ }{
{name: "polish model", mutate: func(cfg *config.Config) { {name: "polish description", mutate: func(cfg *config.Config) {
cfg.Pipeline.Audita.Model = "production" cfg.Pipeline.Audita.TranscriptDescription = "production"
}, wantRuns: [7]int{0, 0, 0, 1, 1, 1, 1}, wantExtractStatus: manifest.StatusStale}, }, wantRuns: [7]int{0, 0, 0, 1, 1, 1, 1}, wantExtractStatus: manifest.StatusStale},
{name: "normalize schema", mutate: func(cfg *config.Config) { {name: "normalize schema", mutate: func(cfg *config.Config) {
cfg.Pipeline.Normalize = &config.NormalizeConfig{OutputSchema: "seriatim.transcript.v2"} cfg.Pipeline.Normalize = &config.NormalizeConfig{OutputSchema: "seriatim.transcript.v2"}
@@ -424,6 +425,69 @@ func TestRefinementSemanticChangesRespectDependencyBranches(t *testing.T) {
} }
} }
func TestOldPolishSemanticEvidenceIsReconsideredOnlyWhenSelected(t *testing.T) {
cfg := testConfig(t)
names := []string{"prepare", "transcribe", "merge", "polish", "normalize", "trim", "render"}
seed := manifest.New(cfg.Session.SessionID, time.Now().UTC())
for _, candidate := range stage.All() {
seed.MarkStageSucceeded(candidate.Name(), time.Now().UTC(), nil)
}
providers := make([]stage.SemanticConfigFingerprinter, len(names))
runs := make([]int, len(names))
selected := make([]stage.Stage, 0, len(names))
for index, name := range names {
providers[index] = canonicalSemanticProvider(t, name)
fingerprint, err := providers[index].SemanticConfigFingerprint(&stage.Env{Config: cfg})
if err != nil {
t.Fatal(err)
}
if name == "polish" {
fingerprint.Version--
}
seed.Stages[name].SemanticConfig = &fingerprint
selected = append(selected, semanticContractRunStub{name: name, provider: providers[index], runs: &runs[index]})
}
store := &manifest.LocalStore{}
if err := store.Save(context.Background(), manifestPathFor(cfg), seed); err != nil {
t.Fatal(err)
}
if _, err := executeStages(context.Background(), cfg, selected[len(selected)-1:], RunOptions{}); err != nil {
t.Fatal(err)
}
if runs[3] != 0 {
t.Fatal("downstream-only execution invoked polish")
}
loaded, err := store.Load(context.Background(), manifestPathFor(cfg))
if err != nil {
t.Fatal(err)
}
if loaded.Stages["polish"].SemanticConfig.Version != seed.Stages["polish"].SemanticConfig.Version {
t.Fatal("downstream-only execution rewrote unselected polish evidence")
}
if _, err := executeStages(context.Background(), cfg, selected, RunOptions{}); err != nil {
t.Fatal(err)
}
if want := []int{0, 0, 0, 1, 1, 1, 1}; !reflect.DeepEqual(runs, want) {
t.Fatalf("runs = %v, want %v", runs, want)
}
loaded, err = store.Load(context.Background(), manifestPathFor(cfg))
if err != nil {
t.Fatal(err)
}
if loaded.Stages["polish"].SemanticConfig.Version != 2 || loaded.Stages["extract"].Status != manifest.StatusStale {
t.Fatalf("old evidence was not replaced with normal dependent invalidation: polish=%#v extract=%#v", loaded.Stages["polish"], loaded.Stages["extract"])
}
for index := range runs {
runs[index] = 0
}
if _, err := executeStages(context.Background(), cfg, selected, RunOptions{}); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(runs, make([]int, len(names))) {
t.Fatalf("unchanged new evidence reran stages: %v", runs)
}
}
func TestDeliverySemanticChangesInvalidateOnlyTheirFixedDependents(t *testing.T) { func TestDeliverySemanticChangesInvalidateOnlyTheirFixedDependents(t *testing.T) {
t.Run("extract contract", func(t *testing.T) { t.Run("extract contract", func(t *testing.T) {
cfg := testConfig(t) cfg := testConfig(t)

View File

@@ -93,7 +93,7 @@ func declarationDefinitionSources(cfg *PipelineConfig, declaration configkit.Pat
seen := map[string]struct{}{} seen := map[string]struct{}{}
for _, change := range cfg.resolution.configkitMetadata.History(declaration) { for _, change := range cfg.resolution.configkitMetadata.History(declaration) {
if change.Origin.Layer != configkit.LayerBase && change.Origin.Layer != configkit.LayerProfile { if change.Origin.Layer != configkit.LayerBase && change.Origin.Layer != configkit.LayerOverlay {
continue continue
} }
for _, location := range change.Origin.Locations { for _, location := range change.Origin.Locations {

View File

@@ -165,21 +165,16 @@ type SeriatimEnvConfig struct {
// AuditaConfig configures audita adapter settings. // AuditaConfig configures audita adapter settings.
type AuditaConfig struct { type AuditaConfig struct {
Binary string `yaml:"binary" json:"binary"` Binary string `yaml:"binary" json:"binary"`
Timeout string `yaml:"timeout" json:"timeout"` Timeout string `yaml:"timeout" json:"timeout"`
LLMAPIKey *configkit.Secret `yaml:"llm_api_key,omitempty" json:"llm_api_key,omitempty"` Credentials []configkit.Secret `yaml:"credentials,omitempty" json:"credentials,omitempty"`
Modules []string `yaml:"modules" json:"modules"` Modules []string `yaml:"modules" json:"modules"`
BaseURL string `yaml:"base_url" json:"base_url"` Overlay string `yaml:"overlay" json:"overlay"`
Model string `yaml:"model" json:"model"` ProposalProfile string `yaml:"proposal_profile" json:"proposal_profile"`
TotalLLMConcurrency *int `yaml:"total_llm_concurrency" json:"total_llm_concurrency"` ValidationProfile string `yaml:"validation_profile" json:"validation_profile"`
ProposalLLMConcurrency *int `yaml:"proposal_llm_concurrency" json:"proposal_llm_concurrency"` TranscriptDescription string `yaml:"transcript_description" json:"transcript_description"`
ValidationModel string `yaml:"validation_model" json:"validation_model"` ConfigPath string `yaml:"config_path" json:"config_path"`
ValidationLLMConcurrency *int `yaml:"validation_llm_concurrency" json:"validation_llm_concurrency"` OutputSchema string `yaml:"output_schema" json:"output_schema"`
TranscriptDescription string `yaml:"transcript_description" json:"transcript_description"`
ConfigPath string `yaml:"config_path" json:"config_path"`
OutputSchema string `yaml:"output_schema" json:"output_schema"`
WorkDirRetention string `yaml:"work_dir_retention" json:"work_dir_retention"`
Report *bool `yaml:"report" json:"report"`
} }
// NormalizeConfig configures normalize-stage transcript schema/output behavior. // NormalizeConfig configures normalize-stage transcript schema/output behavior.
@@ -309,7 +304,7 @@ type ScriptoriumInputConfig struct {
type NotariusConfig struct { type NotariusConfig struct {
Enabled bool `yaml:"enabled" json:"enabled"` Enabled bool `yaml:"enabled" json:"enabled"`
Binary string `yaml:"binary" json:"binary"` Binary string `yaml:"binary" json:"binary"`
LLMAPIKey *configkit.Secret `yaml:"llm_api_key,omitempty" json:"llm_api_key,omitempty"` Credentials []configkit.Secret `yaml:"credentials,omitempty" json:"credentials,omitempty"`
ConfigProfile *string `yaml:"config_profile,omitempty" json:"config_profile,omitempty"` ConfigProfile *string `yaml:"config_profile,omitempty" json:"config_profile,omitempty"`
Resume bool `yaml:"resume,omitempty" json:"resume,omitempty"` Resume bool `yaml:"resume,omitempty" json:"resume,omitempty"`
ChunkCache string `yaml:"chunk_cache,omitempty" json:"chunk_cache,omitempty"` ChunkCache string `yaml:"chunk_cache,omitempty" json:"chunk_cache,omitempty"`

View File

@@ -21,41 +21,39 @@ func (cfg StorageS3Config) MarshalYAML() (any, error) {
}, nil }, nil
} }
// MarshalYAML exposes only the public Audita credential reference name. // MarshalYAML exposes only public Audita credential reference names.
func (cfg AuditaConfig) MarshalYAML() (any, error) { func (cfg AuditaConfig) MarshalYAML() (any, error) {
type safeAudita struct { type safeAudita struct {
Binary string `yaml:"binary"` Binary string `yaml:"binary"`
Timeout string `yaml:"timeout"` Timeout string `yaml:"timeout"`
LLMAPIKey *string `yaml:"llm_api_key,omitempty"` Credentials []string `yaml:"credentials,omitempty"`
Modules []string `yaml:"modules"` Modules *[]string `yaml:"modules,omitempty"`
BaseURL string `yaml:"base_url"` Overlay string `yaml:"overlay"`
Model string `yaml:"model"` ProposalProfile string `yaml:"proposal_profile"`
TotalLLMConcurrency *int `yaml:"total_llm_concurrency"` ValidationProfile string `yaml:"validation_profile"`
ProposalLLMConcurrency *int `yaml:"proposal_llm_concurrency"` TranscriptDescription string `yaml:"transcript_description"`
ValidationModel string `yaml:"validation_model"` ConfigPath string `yaml:"config_path"`
ValidationLLMConcurrency *int `yaml:"validation_llm_concurrency"` OutputSchema string `yaml:"output_schema"`
TranscriptDescription string `yaml:"transcript_description"` }
ConfigPath string `yaml:"config_path"` // A nil pointer omits the override; a pointer to an empty slice disables modules.
OutputSchema string `yaml:"output_schema"` var modules *[]string
WorkDirRetention string `yaml:"work_dir_retention"` if cfg.Modules != nil {
Report *bool `yaml:"report"` modules = &cfg.Modules
} }
return safeAudita{ return safeAudita{
Binary: cfg.Binary, Timeout: cfg.Timeout, LLMAPIKey: secretReferenceName(cfg.LLMAPIKey), Binary: cfg.Binary, Timeout: cfg.Timeout, Credentials: secretReferenceNames(cfg.Credentials),
Modules: cfg.Modules, BaseURL: cfg.BaseURL, Model: cfg.Model, Modules: modules, Overlay: cfg.Overlay, ProposalProfile: cfg.ProposalProfile,
TotalLLMConcurrency: cfg.TotalLLMConcurrency, ProposalLLMConcurrency: cfg.ProposalLLMConcurrency, ValidationProfile: cfg.ValidationProfile, TranscriptDescription: cfg.TranscriptDescription,
ValidationModel: cfg.ValidationModel, ValidationLLMConcurrency: cfg.ValidationLLMConcurrency, ConfigPath: cfg.ConfigPath, OutputSchema: cfg.OutputSchema,
TranscriptDescription: cfg.TranscriptDescription, ConfigPath: cfg.ConfigPath,
OutputSchema: cfg.OutputSchema, WorkDirRetention: cfg.WorkDirRetention, Report: cfg.Report,
}, nil }, nil
} }
// MarshalYAML exposes only the public Notarius credential reference name. // MarshalYAML exposes only public Notarius credential reference names.
func (cfg NotariusConfig) MarshalYAML() (any, error) { func (cfg NotariusConfig) MarshalYAML() (any, error) {
type safeNotarius struct { type safeNotarius struct {
Enabled bool `yaml:"enabled"` Enabled bool `yaml:"enabled"`
Binary string `yaml:"binary"` Binary string `yaml:"binary"`
LLMAPIKey *string `yaml:"llm_api_key,omitempty"` Credentials []string `yaml:"credentials,omitempty"`
ConfigProfile *string `yaml:"config_profile,omitempty"` ConfigProfile *string `yaml:"config_profile,omitempty"`
Resume bool `yaml:"resume,omitempty"` Resume bool `yaml:"resume,omitempty"`
ChunkCache string `yaml:"chunk_cache,omitempty"` ChunkCache string `yaml:"chunk_cache,omitempty"`
@@ -67,7 +65,7 @@ func (cfg NotariusConfig) MarshalYAML() (any, error) {
Outputs map[string]NotariusOutputConfig `yaml:"outputs"` Outputs map[string]NotariusOutputConfig `yaml:"outputs"`
} }
return safeNotarius{ return safeNotarius{
Enabled: cfg.Enabled, Binary: cfg.Binary, LLMAPIKey: secretReferenceName(cfg.LLMAPIKey), Enabled: cfg.Enabled, Binary: cfg.Binary, Credentials: secretReferenceNames(cfg.Credentials),
ConfigProfile: cfg.ConfigProfile, ConfigProfile: cfg.ConfigProfile,
Resume: cfg.Resume, ChunkCache: cfg.ChunkCache, Resume: cfg.Resume, ChunkCache: cfg.ChunkCache,
ConfigPath: cfg.ConfigPath, PipelineID: cfg.PipelineID, Timeout: cfg.Timeout, ConfigPath: cfg.ConfigPath, PipelineID: cfg.PipelineID, Timeout: cfg.Timeout,
@@ -75,6 +73,17 @@ func (cfg NotariusConfig) MarshalYAML() (any, error) {
}, nil }, nil
} }
func secretReferenceNames(secrets []configkit.Secret) []string {
if secrets == nil {
return nil
}
names := make([]string, len(secrets))
for index, secret := range secrets {
names[index] = secret.EnvName()
}
return names
}
func secretReferenceName(secret *configkit.Secret) *string { func secretReferenceName(secret *configkit.Secret) *string {
if secret == nil { if secret == nil {
return nil return nil

View File

@@ -0,0 +1,33 @@
package config
import (
"reflect"
"testing"
"gopkg.in/yaml.v3"
)
func TestAuditaYAMLPreservesModuleSelection(t *testing.T) {
for _, tc := range []struct {
name string
modules []string
}{
{name: "omitted"},
{name: "explicit empty", modules: []string{}},
{name: "ordered repetitions", modules: []string{"grammar", "names", "grammar"}},
} {
t.Run(tc.name, func(t *testing.T) {
data, err := yaml.Marshal(AuditaConfig{Modules: tc.modules})
if err != nil {
t.Fatal(err)
}
var decoded AuditaConfig
if err := yaml.Unmarshal(data, &decoded); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(decoded.Modules, tc.modules) {
t.Fatalf("modules = %#v, want %#v; YAML:\n%s", decoded.Modules, tc.modules, data)
}
})
}
}

View File

@@ -30,7 +30,6 @@ const (
DefaultAuditaBinary = "audita" DefaultAuditaBinary = "audita"
DefaultAuditaTimeout = "3h" DefaultAuditaTimeout = "3h"
DefaultAuditaReport = true
DefaultNotariusBinary = "notarius" DefaultNotariusBinary = "notarius"
DefaultNotariusTimeout = "3h" DefaultNotariusTimeout = "3h"
// MaxNotariusReferenceBindings is the maximum number of CLI reference // MaxNotariusReferenceBindings is the maximum number of CLI reference

View File

@@ -14,21 +14,21 @@ const (
effectivePipelineDigestVersion = "narratio-effective-pipeline-v3\n" effectivePipelineDigestVersion = "narratio-effective-pipeline-v3\n"
) )
// PipelineProfileProvenance identifies the profile selected while resolving a // PipelineOverlayProvenance identifies the overlay selected while resolving a
// pipeline. It contains only non-secret selection metadata. // pipeline. It contains only non-secret selection metadata.
type PipelineProfileProvenance struct { type PipelineOverlayProvenance struct {
Name string Name string
Source string Source string
OverlayPath string OverlayPath string
} }
// SelectedPipelineProfile reports the profile used to resolve cfg, if any. // SelectedPipelineOverlay reports the overlay used to resolve cfg, if any.
func SelectedPipelineProfile(cfg *PipelineConfig) (*PipelineProfileProvenance, bool) { func SelectedPipelineOverlay(cfg *PipelineConfig) (*PipelineOverlayProvenance, bool) {
if cfg == nil || cfg.resolution == nil || cfg.resolution.selectedProfile == nil { if cfg == nil || cfg.resolution == nil || cfg.resolution.selectedOverlay == nil {
return nil, false return nil, false
} }
selection := cfg.resolution.selectedProfile selection := cfg.resolution.selectedOverlay
return &PipelineProfileProvenance{Name: selection.name, Source: selection.source, OverlayPath: selection.overlayPath}, true return &PipelineOverlayProvenance{Name: selection.name, Source: selection.source, OverlayPath: selection.overlayPath}, true
} }
// EffectivePipelineDigest reports the deterministic secret-free digest for a // EffectivePipelineDigest reports the deterministic secret-free digest for a

View File

@@ -401,8 +401,8 @@ func pipelineSourceRole(cfg *PipelineConfig, source string) string {
if source == cfg.resolution.rootPath { if source == cfg.resolution.rootPath {
return "root" return "root"
} }
if cfg.resolution.selectedProfile != nil && source == cfg.resolution.selectedProfile.overlayPath { if cfg.resolution.selectedOverlay != nil && source == cfg.resolution.selectedOverlay.overlayPath {
return "profile" return "overlay"
} }
for _, imported := range cfg.resolution.imports { for _, imported := range cfg.resolution.imports {
if source == imported { if source == imported {

View File

@@ -15,14 +15,14 @@ func LoadPipeline(path string) (*PipelineConfig, error) {
return LoadPipelineWithOptions(path, PipelineLoadOptions{}) return LoadPipelineWithOptions(path, PipelineLoadOptions{})
} }
// PipelineLoadOptions carries an optional explicit profile selection. Nil, // PipelineLoadOptions carries an optional explicit overlay selection. Nil,
// empty, and the exact name "default" select the base configuration. // empty, and the exact name "default" select the base configuration.
type PipelineLoadOptions struct { type PipelineLoadOptions struct {
Profile *string Overlay *string
} }
// LoadPipelineWithOptions loads pipeline configuration with strict field // LoadPipelineWithOptions loads pipeline configuration with strict field
// checking and optional named-profile selection. // checking and optional named-overlay selection.
func LoadPipelineWithOptions(path string, opts PipelineLoadOptions) (*PipelineConfig, error) { func LoadPipelineWithOptions(path string, opts PipelineLoadOptions) (*PipelineConfig, error) {
cfg, err := loadPipelineWithConfigKit(path, opts) cfg, err := loadPipelineWithConfigKit(path, opts)
if err != nil { if err != nil {
@@ -31,20 +31,20 @@ func LoadPipelineWithOptions(path string, opts PipelineLoadOptions) (*PipelineCo
return finalizeLoadedPipeline(path, cfg) return finalizeLoadedPipeline(path, cfg)
} }
// LoadPipelineProfilePair resolves two profiles as independent ConfigKit loads. // LoadPipelineOverlayPair resolves two overlays as independent ConfigKit loads.
func LoadPipelineProfilePair(path, leftProfile, rightProfile string) (*PipelineConfig, *PipelineConfig, error) { func LoadPipelineOverlayPair(path, leftOverlay, rightOverlay string) (*PipelineConfig, *PipelineConfig, error) {
if leftProfile == rightProfile { if leftOverlay == rightOverlay {
return nil, nil, fmt.Errorf("load pipeline profiles: left and right profile selections must differ") return nil, nil, fmt.Errorf("load pipeline overlays: left and right overlay selections must differ")
} }
leftOptions := PipelineLoadOptions{Profile: &leftProfile} leftOptions := PipelineLoadOptions{Overlay: &leftOverlay}
rightOptions := PipelineLoadOptions{Profile: &rightProfile} rightOptions := PipelineLoadOptions{Overlay: &rightOverlay}
left, err := LoadPipelineWithOptions(path, leftOptions) left, err := LoadPipelineWithOptions(path, leftOptions)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("load left pipeline profile: %w", err) return nil, nil, fmt.Errorf("load left pipeline overlay: %w", err)
} }
right, err := LoadPipelineWithOptions(path, rightOptions) right, err := LoadPipelineWithOptions(path, rightOptions)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("load right pipeline profile: %w", err) return nil, nil, fmt.Errorf("load right pipeline overlay: %w", err)
} }
return left, right, nil return left, right, nil
} }
@@ -76,7 +76,7 @@ func LoadSession(path string) (*SessionConfig, error) {
type SessionLoadOptions struct { type SessionLoadOptions struct {
SessionID string SessionID string
PreviousSessionID string PreviousSessionID string
Profile *string Overlay *string
} }
// LoadSessionWithOptions loads session configuration from a YAML file with // LoadSessionWithOptions loads session configuration from a YAML file with
@@ -143,7 +143,7 @@ func Load(pipelinePath string, paths ...string) (*Config, error) {
// LoadWithSessionOptions loads and resolves combined pipeline, campaign, and // LoadWithSessionOptions loads and resolves combined pipeline, campaign, and
// session configuration with expected session identity checks. // session configuration with expected session identity checks.
func LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath string, sessionOpts SessionLoadOptions) (*Config, error) { func LoadWithSessionOptions(pipelinePath, campaignPath, sessionPath string, sessionOpts SessionLoadOptions) (*Config, error) {
pipelineCfg, err := LoadPipelineWithOptions(pipelinePath, PipelineLoadOptions{Profile: sessionOpts.Profile}) pipelineCfg, err := LoadPipelineWithOptions(pipelinePath, PipelineLoadOptions{Overlay: sessionOpts.Overlay})
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -93,7 +93,7 @@ func TestCredentialValuesNeverEnterEffectiveProjectionOrDigest(t *testing.T) {
t.Setenv("NARRATIO_TEST_SECRET_KEY", firstCanary) t.Setenv("NARRATIO_TEST_SECRET_KEY", firstCanary)
t.Setenv("NARRATIO_TEST_AUDITA_KEY", firstCanary) t.Setenv("NARRATIO_TEST_AUDITA_KEY", firstCanary)
t.Setenv("NARRATIO_TEST_NOTARIUS_KEY", firstCanary) t.Setenv("NARRATIO_TEST_NOTARIUS_KEY", firstCanary)
pipelineYAML := strings.Replace(testPipelineBaseYAML, "audita:\n binary: audita\n", "audita:\n binary: audita\n llm_api_key: NARRATIO_TEST_AUDITA_KEY\n", 1) + ` pipelineYAML := strings.Replace(testPipelineBaseYAML, "audita:\n binary: audita\n", "audita:\n binary: audita\n credentials: [NARRATIO_TEST_AUDITA_KEY]\n", 1) + `
storage: storage:
backend: s3 backend: s3
s3: s3:
@@ -102,7 +102,7 @@ storage:
secret_access_key: NARRATIO_TEST_SECRET_KEY secret_access_key: NARRATIO_TEST_SECRET_KEY
notarius: notarius:
enabled: false enabled: false
llm_api_key: NARRATIO_TEST_NOTARIUS_KEY credentials: [NARRATIO_TEST_NOTARIUS_KEY]
config_profile: "" config_profile: ""
` `
pipelinePath, _ := writeConfigFiles(t, pipelineYAML, testSessionBaseYAML) pipelinePath, _ := writeConfigFiles(t, pipelineYAML, testSessionBaseYAML)
@@ -146,8 +146,8 @@ notarius:
} }
var roundTrip struct { var roundTrip struct {
Notarius *struct { Notarius *struct {
LLMAPIKey *string `yaml:"llm_api_key"` Credentials []string `yaml:"credentials"`
ConfigProfile *string `yaml:"config_profile"` ConfigProfile *string `yaml:"config_profile"`
} `yaml:"notarius"` } `yaml:"notarius"`
} }
if err := yaml.Unmarshal(firstYAML, &roundTrip); err != nil { if err := yaml.Unmarshal(firstYAML, &roundTrip); err != nil {
@@ -156,8 +156,8 @@ notarius:
if roundTrip.Notarius == nil || roundTrip.Notarius.ConfigProfile == nil || *roundTrip.Notarius.ConfigProfile != "" { if roundTrip.Notarius == nil || roundTrip.Notarius.ConfigProfile == nil || *roundTrip.Notarius.ConfigProfile != "" {
t.Fatalf("round-trip config profile = %#v, want explicit empty", roundTrip.Notarius) t.Fatalf("round-trip config profile = %#v, want explicit empty", roundTrip.Notarius)
} }
if roundTrip.Notarius.LLMAPIKey == nil || *roundTrip.Notarius.LLMAPIKey != "NARRATIO_TEST_NOTARIUS_KEY" { if len(roundTrip.Notarius.Credentials) != 1 || roundTrip.Notarius.Credentials[0] != "NARRATIO_TEST_NOTARIUS_KEY" {
t.Fatalf("round-trip credential reference = %#v, want safe public name", roundTrip.Notarius.LLMAPIKey) t.Fatalf("round-trip credential reference = %#v, want safe public name", roundTrip.Notarius.Credentials)
} }
t.Setenv("NARRATIO_TEST_ACCESS_KEY", secondCanary) t.Setenv("NARRATIO_TEST_ACCESS_KEY", secondCanary)
@@ -358,7 +358,7 @@ func TestExamplesLoadAndValidate(t *testing.T) {
t.Run(profile.name, func(t *testing.T) { t.Run(profile.name, func(t *testing.T) {
options := PipelineLoadOptions{} options := PipelineLoadOptions{}
if profile.selection != "" { if profile.selection != "" {
options.Profile = &profile.selection options.Overlay = &profile.selection
} }
pipeline, err := LoadPipelineWithOptions(pipelinePath, options) pipeline, err := LoadPipelineWithOptions(pipelinePath, options)
if err != nil { if err != nil {
@@ -375,18 +375,18 @@ func TestExamplesLoadAndValidate(t *testing.T) {
if err := Validate(cfg); err != nil { if err := Validate(cfg); err != nil {
t.Fatalf("validate split bundle: %v", err) t.Fatalf("validate split bundle: %v", err)
} }
if cfg.Pipeline.Audita.Model != profile.model { if cfg.Pipeline.Audita.ProposalProfile != profile.model {
t.Fatalf("audita model = %q, want %q", cfg.Pipeline.Audita.Model, profile.model) t.Fatalf("audita proposal profile = %q, want %q", cfg.Pipeline.Audita.ProposalProfile, profile.model)
} }
if cfg.Pipeline.Audita.LLMAPIKey != nil || cfg.Pipeline.Storage.Backend != StorageBackendLocal || cfg.Pipeline.Storage.S3 != nil { if len(cfg.Pipeline.Audita.Credentials) != 0 || cfg.Pipeline.Storage.Backend != StorageBackendLocal || cfg.Pipeline.Storage.S3 != nil {
t.Fatalf("split bundle must remain offline and secret-free: audita=%#v storage=%#v", cfg.Pipeline.Audita, cfg.Pipeline.Storage) t.Fatalf("split bundle must remain offline and secret-free: audita=%#v storage=%#v", cfg.Pipeline.Audita, cfg.Pipeline.Storage)
} }
selectedProfile, selected := SelectedPipelineProfile(cfg.Pipeline) selectedOverlay, selected := SelectedPipelineOverlay(cfg.Pipeline)
if profile.selection == "" && selected { if profile.selection == "" && selected {
t.Fatalf("production base unexpectedly selected profile %#v", selectedProfile) t.Fatalf("production base unexpectedly selected overlay %#v", selectedOverlay)
} }
if profile.selection != "" && (!selected || selectedProfile.Name != profile.selection) { if profile.selection != "" && (!selected || selectedOverlay.Name != profile.selection) {
t.Fatalf("selected profile = %#v, want %q", selectedProfile, profile.selection) t.Fatalf("selected overlay = %#v, want %q", selectedOverlay, profile.selection)
} }
for _, key := range []string{ for _, key := range []string{
"session_recap", "session_recap",

View File

@@ -58,8 +58,10 @@ notarius:
func TestNotariusCredentialReferenceLoading(t *testing.T) { func TestNotariusCredentialReferenceLoading(t *testing.T) {
const envName = "NARRATIO_TEST_NOTARIUS_KEY" const envName = "NARRATIO_TEST_NOTARIUS_KEY"
const secondName = "NARRATIO_TEST_NOTARIUS_SECOND_KEY"
const canary = "notarius-credential-canary" const canary = "notarius-credential-canary"
t.Setenv(envName, canary) t.Setenv(envName, canary)
t.Setenv(secondName, "second-canary")
tests := []struct { tests := []struct {
name string name string
@@ -67,8 +69,9 @@ func TestNotariusCredentialReferenceLoading(t *testing.T) {
wantNil bool wantNil bool
}{ }{
{name: "omitted", wantNil: true}, {name: "omitted", wantNil: true},
{name: "null", credential: " llm_api_key: null\n", wantNil: true}, {name: "null", credential: " credentials: null\n", wantNil: true},
{name: "custom reference", credential: " llm_api_key: " + envName + "\n"}, {name: "empty", credential: " credentials: []\n"},
{name: "custom references", credential: " credentials: [" + envName + ", " + secondName + "]\n"},
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
@@ -81,15 +84,19 @@ func TestNotariusCredentialReferenceLoading(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if test.wantNil { if test.wantNil && cfg.Notarius.Credentials != nil {
if cfg.Notarius.LLMAPIKey != nil { t.Fatal("credential list should be nil")
t.Fatal("credential reference should be nil") }
} if test.name == "empty" && len(cfg.Notarius.Credentials) == 0 {
return return
} }
if cfg.Notarius.LLMAPIKey == nil || cfg.Notarius.LLMAPIKey.EnvName() != envName || if test.wantNil {
!cfg.Notarius.LLMAPIKey.IsResolved() || cfg.Notarius.LLMAPIKey.Value() != canary { return
t.Fatal("credential reference was not loaded and resolved") }
if len(cfg.Notarius.Credentials) != 2 ||
cfg.Notarius.Credentials[0].EnvName() != envName || cfg.Notarius.Credentials[0].Value() != canary ||
cfg.Notarius.Credentials[1].EnvName() != secondName || cfg.Notarius.Credentials[1].Value() != "second-canary" {
t.Fatal("credential references were not loaded and resolved")
} }
}) })
} }
@@ -110,7 +117,7 @@ func TestNotariusCredentialReferenceFailures(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
path := filepath.Join(t.TempDir(), "pipeline.yml") path := filepath.Join(t.TempDir(), "pipeline.yml")
pipelineYAML := testPipelineBaseYAML + "\nnotarius:\n enabled: false\n llm_api_key: " + test.reference + "\n" pipelineYAML := testPipelineBaseYAML + "\nnotarius:\n enabled: false\n credentials: [" + test.reference + "]\n"
if err := os.WriteFile(path, []byte(pipelineYAML), 0o644); err != nil { if err := os.WriteFile(path, []byte(pipelineYAML), 0o644); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -122,6 +129,17 @@ func TestNotariusCredentialReferenceFailures(t *testing.T) {
} }
} }
func TestNotariusRejectsRetiredCredentialField(t *testing.T) {
path := filepath.Join(t.TempDir(), "pipeline.yml")
pipelineYAML := testPipelineBaseYAML + "\nnotarius:\n llm_api_key: NARRATIO_TEST_NOTARIUS_KEY\n"
if err := os.WriteFile(path, []byte(pipelineYAML), 0o644); err != nil {
t.Fatal(err)
}
if _, err := LoadPipeline(path); err == nil || !strings.Contains(err.Error(), "decode.unknown_field") {
t.Fatalf("LoadPipeline() error = %v, want unknown field", err)
}
}
func TestNotariusEnabledDefaultsAndPathResolution(t *testing.T) { func TestNotariusEnabledDefaultsAndPathResolution(t *testing.T) {
dir := t.TempDir() dir := t.TempDir()
pipelinePath := filepath.Join(dir, "deployment", "pipeline.yml") pipelinePath := filepath.Join(dir, "deployment", "pipeline.yml")

View File

@@ -16,7 +16,7 @@ type pipelineResolutionMetadata struct {
rootPath string rootPath string
imports []string imports []string
sources []string sources []string
selectedProfile *pipelineProfileSelection selectedOverlay *pipelineOverlaySelection
effectiveDigest string effectiveDigest string
logicalNotariusConfig string logicalNotariusConfig string
logicalNotariusWorking string logicalNotariusWorking string
@@ -29,7 +29,7 @@ type pipelineResolutionMetadata struct {
configkitSources []configkit.SourceInfo configkitSources []configkit.SourceInfo
} }
type pipelineProfileSelection struct { type pipelineOverlaySelection struct {
name string name string
source string source string
overlayPath string overlayPath string
@@ -41,8 +41,8 @@ type pipelineFieldOwnership struct {
} }
func loadPipelineWithConfigKit(path string, opts PipelineLoadOptions) (*PipelineConfig, error) { func loadPipelineWithConfigKit(path string, opts PipelineLoadOptions) (*PipelineConfig, error) {
profile := selectedPipelineProfileName(opts) overlay := selectedPipelineOverlayName(opts)
result, err := loadPipelineConfigKitResult(path, profile) result, err := loadPipelineConfigKitResult(path, overlay)
if err != nil { if err != nil {
return nil, describePipelineLoadError(err) return nil, describePipelineLoadError(err)
} }
@@ -55,10 +55,10 @@ func loadPipelineWithConfigKit(path string, opts PipelineLoadOptions) (*Pipeline
return &cfg, nil return &cfg, nil
} }
func loadPipelineConfigKitResult(path, profile string) (*configkit.Result[PipelineConfig], error) { func loadPipelineConfigKitResult(path, overlay string) (*configkit.Result[PipelineConfig], error) {
return configkit.Load(configkit.File(path), configkit.Options[PipelineConfig]{ return configkit.Load(configkit.File(path), configkit.Options[PipelineConfig]{
Imports: true, Imports: true,
Profile: profile, Overlay: overlay,
Definition: configkit.Definition[PipelineConfig]{ Definition: configkit.Definition[PipelineConfig]{
Defaults: pipelineConfigDefaults, Defaults: pipelineConfigDefaults,
Resolve: resolvePipelineConfig, Resolve: resolvePipelineConfig,
@@ -104,11 +104,11 @@ func describeConfigKitLoadError(kind string, err error) error {
return fmt.Errorf("load %s config: strict decode failed or validation failed: %w: %s", kind, err, strings.TrimSpace(diagnostics.String())) return fmt.Errorf("load %s config: strict decode failed or validation failed: %w: %s", kind, err, strings.TrimSpace(diagnostics.String()))
} }
func selectedPipelineProfileName(opts PipelineLoadOptions) string { func selectedPipelineOverlayName(opts PipelineLoadOptions) string {
if opts.Profile == nil || *opts.Profile == "" || *opts.Profile == "default" { if opts.Overlay == nil || *opts.Overlay == "" || *opts.Overlay == "default" {
return "" return ""
} }
return *opts.Profile return *opts.Overlay
} }
func pipelineConfigDefaults() PipelineConfig { func pipelineConfigDefaults() PipelineConfig {
@@ -132,7 +132,7 @@ func pipelineConfigDefaults() PipelineConfig {
OutputSchema: DefaultSeriatimOutputSchema, CoalesceGap: float64Ptr(DefaultSeriatimCoalesceGap), OutputSchema: DefaultSeriatimOutputSchema, CoalesceGap: float64Ptr(DefaultSeriatimCoalesceGap),
Report: boolPtr(DefaultSeriatimReport), Report: boolPtr(DefaultSeriatimReport),
}, },
Audita: AuditaConfig{Binary: DefaultAuditaBinary, Timeout: DefaultAuditaTimeout, Report: boolPtr(DefaultAuditaReport)}, Audita: AuditaConfig{Binary: DefaultAuditaBinary, Timeout: DefaultAuditaTimeout},
Normalize: &NormalizeConfig{OutputPath: DefaultNormalizeOutputPath, OutputSchema: DefaultNormalizeOutputSchema, Report: boolPtr(DefaultNormalizeReport)}, Normalize: &NormalizeConfig{OutputPath: DefaultNormalizeOutputPath, OutputSchema: DefaultNormalizeOutputSchema, Report: boolPtr(DefaultNormalizeReport)},
Trim: &TrimConfig{ Trim: &TrimConfig{
Enabled: boolPtr(DefaultTrimEnabled), OutputPath: DefaultTrimOutputPath, Enabled: boolPtr(DefaultTrimEnabled), OutputPath: DefaultTrimOutputPath,
@@ -282,8 +282,8 @@ func pipelineMetadataFromConfigKit(cfg *PipelineConfig, result *configkit.Result
} else if source.Layer == configkit.LayerBase { } else if source.Layer == configkit.LayerBase {
resolved.imports = append(resolved.imports, path) resolved.imports = append(resolved.imports, path)
} }
if source.Layer == configkit.LayerProfile { if source.Layer == configkit.LayerOverlay {
resolved.selectedProfile = &pipelineProfileSelection{name: selectedPipelineProfileName(opts), source: "explicit", overlayPath: path} resolved.selectedOverlay = &pipelineOverlaySelection{name: selectedPipelineOverlayName(opts), source: "explicit", overlayPath: path}
} }
} }
detailed, err := pipelineMetadataPaths(cfg) detailed, err := pipelineMetadataPaths(cfg)
@@ -347,7 +347,7 @@ func rejectDuplicateBaseDefinitions(metadata configkit.Metadata, sources []confi
pathsByID[source.ID] = source.Path pathsByID[source.ID] = source.Path
} }
// Enumerate retained declarations, not just surviving effective keys. Loading // Enumerate retained declarations, not just surviving effective keys. Loading
// the base separately would also resolve credentials removed by the profile. // the base separately would also resolve credentials removed by the overlay.
// ConfigKit returns canonical JSON Pointers in deterministic order. // ConfigKit returns canonical JSON Pointers in deterministic order.
for _, path := range metadata.HistoricalPaths() { for _, path := range metadata.HistoricalPaths() {
parts := strings.Split(path.String(), "/") parts := strings.Split(path.String(), "/")

View File

@@ -8,7 +8,7 @@ import (
"testing" "testing"
) )
func TestPipelineConfigKitImportsProfileAndBaseSelection(t *testing.T) { func TestPipelineConfigKitImportsOverlayAndBaseSelection(t *testing.T) {
dir := t.TempDir() dir := t.TempDir()
writePipelineFixture(t, dir, "pipeline.yml", `configkit: writePipelineFixture(t, dir, "pipeline.yml", `configkit:
imports: imports:
@@ -24,33 +24,62 @@ whisperx:
enabled: false enabled: false
output_path: artifacts/recap.md output_path: artifacts/recap.md
`) `)
writePipelineFixture(t, dir, "profiles/testing.yml", "workspace:\n root: /srv/testing\n") writePipelineFixture(t, dir, "overlays/testing.yml", "workspace:\n root: /srv/testing\n")
writePipelineFixture(t, dir, "profiles/unselected.yml", "unknown: [\n") writePipelineFixture(t, dir, "overlays/identical.yml", "workspace:\n root: /srv/base\n")
writePipelineFixture(t, dir, "overlays/unselected.yml", "unknown: [\n")
root := filepath.Join(dir, "pipeline.yml") root := filepath.Join(dir, "pipeline.yml")
var baseDigest string
for _, profile := range []*string{nil, stringPointer(""), stringPointer("default")} { for _, profile := range []*string{nil, stringPointer(""), stringPointer("default")} {
cfg, err := LoadPipelineWithOptions(root, PipelineLoadOptions{Profile: profile}) cfg, err := LoadPipelineWithOptions(root, PipelineLoadOptions{Overlay: profile})
if err != nil { if err != nil {
t.Fatalf("load base selection %#v: %v", profile, err) t.Fatalf("load base selection %#v: %v", profile, err)
} }
if cfg.Workspace.Root != "/srv/base" { if cfg.Workspace.Root != "/srv/base" {
t.Fatalf("base workspace = %q", cfg.Workspace.Root) t.Fatalf("base workspace = %q", cfg.Workspace.Root)
} }
if baseDigest == "" {
baseDigest = EffectivePipelineDigest(cfg)
} else if EffectivePipelineDigest(cfg) != baseDigest {
t.Fatal("equivalent base selections changed effective digest")
}
}
identical := "identical"
unchanged, err := LoadPipelineWithOptions(root, PipelineLoadOptions{Overlay: &identical})
if err != nil {
t.Fatal(err)
}
if EffectivePipelineDigest(unchanged) != baseDigest {
t.Fatal("equivalent overlay changed effective digest")
} }
selected := "testing" selected := "testing"
cfg, err := LoadPipelineWithOptions(root, PipelineLoadOptions{Profile: &selected}) cfg, err := LoadPipelineWithOptions(root, PipelineLoadOptions{Overlay: &selected})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if cfg.Workspace.Root != "/srv/testing" || len(EffectivePipelineImports(cfg)) != 2 { if cfg.Workspace.Root != "/srv/testing" || len(EffectivePipelineImports(cfg)) != 2 {
t.Fatalf("profiled pipeline = %#v, imports=%#v", cfg.Workspace, EffectivePipelineImports(cfg)) t.Fatalf("profiled pipeline = %#v, imports=%#v", cfg.Workspace, EffectivePipelineImports(cfg))
} }
profile, ok := SelectedPipelineProfile(cfg) profile, ok := SelectedPipelineOverlay(cfg)
if !ok || profile.Name != "testing" || profile.OverlayPath != filepath.Join(dir, "profiles", "testing.yml") { if !ok || profile.Name != "testing" || profile.OverlayPath != filepath.Join(dir, "overlays", "testing.yml") {
t.Fatalf("selected profile = %#v, %v", profile, ok) t.Fatalf("selected profile = %#v, %v", profile, ok)
} }
} }
func TestPipelineOverlayDoesNotDiscoverLegacyDirectory(t *testing.T) {
dir := t.TempDir()
writePipelineFixture(t, dir, "pipeline.yml", "configkit:\n imports:\n - path: profiles/shared.yml\n")
writePipelineFixture(t, dir, "profiles/shared.yml", "workspace:\n root: /srv/base\n")
writePipelineFixture(t, dir, "profiles/testing.yml", "workspace:\n root: /srv/old\n")
if base, err := LoadPipeline(filepath.Join(dir, "pipeline.yml")); err != nil || base.Workspace.Root != "/srv/base" {
t.Fatalf("explicit import from profiles directory = %#v, %v", base, err)
}
selected := "testing"
if _, err := LoadPipelineWithOptions(filepath.Join(dir, "pipeline.yml"), PipelineLoadOptions{Overlay: &selected}); err == nil || !strings.Contains(err.Error(), "overlay.missing") {
t.Fatalf("legacy selected file result = %v, want missing overlay", err)
}
}
func TestPipelineConfigKitRejectsDuplicateBaseDeclarations(t *testing.T) { func TestPipelineConfigKitRejectsDuplicateBaseDeclarations(t *testing.T) {
for _, test := range []struct { for _, test := range []struct {
name, first, second, clearedContainer string name, first, second, clearedContainer string
@@ -69,14 +98,14 @@ whisperx:
`) `)
writePipelineFixture(t, dir, "first.yml", test.first) writePipelineFixture(t, dir, "first.yml", test.first)
writePipelineFixture(t, dir, "second.yml", test.second) writePipelineFixture(t, dir, "second.yml", test.second)
writePipelineFixture(t, dir, "profiles/clear-container.yml", test.clearedContainer) writePipelineFixture(t, dir, "overlays/clear-container.yml", test.clearedContainer)
writePipelineFixture(t, dir, "profiles/clear-scriptorium.yml", "scriptorium: null\n") writePipelineFixture(t, dir, "overlays/clear-scriptorium.yml", "scriptorium: null\n")
for _, profile := range []string{"", "clear-container", "clear-scriptorium"} { for _, profile := range []string{"", "clear-container", "clear-scriptorium"} {
t.Run(profile, func(t *testing.T) { t.Run(profile, func(t *testing.T) {
options := PipelineLoadOptions{} options := PipelineLoadOptions{}
if profile != "" { if profile != "" {
options.Profile = &profile options.Overlay = &profile
} }
_, err := LoadPipelineWithOptions(filepath.Join(dir, "pipeline.yml"), options) _, err := LoadPipelineWithOptions(filepath.Join(dir, "pipeline.yml"), options)
if err == nil || !strings.Contains(err.Error(), "declared by multiple base files") || if err == nil || !strings.Contains(err.Error(), "declared by multiple base files") ||
@@ -89,7 +118,7 @@ whisperx:
} }
} }
func TestPipelineProfileDoesNotRequireUnusedBaseCredentials(t *testing.T) { func TestPipelineOverlayDoesNotRequireUnusedBaseCredentials(t *testing.T) {
const production = "NARRATIO_PROFILE_UNUSED_PROD_KEY" const production = "NARRATIO_PROFILE_UNUSED_PROD_KEY"
const testingKey = "NARRATIO_PROFILE_TEST_KEY" const testingKey = "NARRATIO_PROFILE_TEST_KEY"
t.Setenv(production, "") t.Setenv(production, "")
@@ -100,25 +129,72 @@ func TestPipelineProfileDoesNotRequireUnusedBaseCredentials(t *testing.T) {
for _, credential := range []string{testingKey, "null"} { for _, credential := range []string{testingKey, "null"} {
t.Run(credential, func(t *testing.T) { t.Run(credential, func(t *testing.T) {
dir := t.TempDir() dir := t.TempDir()
root := writePipelineFixture(t, dir, "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\naudita:\n llm_api_key: "+production+"\n") root := writePipelineFixture(t, dir, "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\naudita:\n credentials: ["+production+"]\n")
writePipelineFixture(t, dir, "profiles/testing.yml", "audita:\n llm_api_key: "+credential+"\n") selected := "[" + credential + "]"
if credential == "null" {
selected = credential
}
writePipelineFixture(t, dir, "overlays/testing.yml", "audita:\n credentials: "+selected+"\n")
profile := "testing" profile := "testing"
cfg, err := LoadPipelineWithOptions(root, PipelineLoadOptions{Profile: &profile}) cfg, err := LoadPipelineWithOptions(root, PipelineLoadOptions{Overlay: &profile})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if credential == "null" { if credential == "null" {
if cfg.Audita.LLMAPIKey != nil { if len(cfg.Audita.Credentials) != 0 {
t.Fatal("profile did not remove the base credential") t.Fatal("profile did not remove the base credential")
} }
} else if cfg.Audita.LLMAPIKey == nil || cfg.Audita.LLMAPIKey.EnvName() != testingKey || !cfg.Audita.LLMAPIKey.IsResolved() { } else if len(cfg.Audita.Credentials) != 1 || cfg.Audita.Credentials[0].EnvName() != testingKey || !cfg.Audita.Credentials[0].IsResolved() {
t.Fatal("profile credential was not resolved") t.Fatal("profile credential was not resolved")
} }
}) })
} }
} }
func TestNotariusCredentialProfileReplacementAndProvenance(t *testing.T) { func TestAuditaModulesPreserveOmittedEmptyAndReplacementSelections(t *testing.T) {
for _, test := range []struct {
name, base, overlay string
wantNil bool
want []string
}{
{name: "omitted", wantNil: true},
{name: "null", base: " modules: null\n", wantNil: true},
{name: "empty", base: " modules: []\n", want: []string{}},
{name: "overlay empty", base: " modules: [glossary]\n", overlay: "audita:\n modules: []\n", want: []string{}},
{name: "overlay order", base: " modules: []\n", overlay: "audita:\n modules: [grammar, glossary, grammar]\n", want: []string{"grammar", "glossary", "grammar"}},
} {
t.Run(test.name, func(t *testing.T) {
dir := t.TempDir()
root := writePipelineFixture(t, dir, "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\naudita:\n binary: audita\n"+test.base)
options := PipelineLoadOptions{}
if test.overlay != "" {
writePipelineFixture(t, dir, "overlays/testing.yml", test.overlay)
selection := "testing"
options.Overlay = &selection
}
cfg, err := LoadPipelineWithOptions(root, options)
if err != nil {
t.Fatal(err)
}
if (cfg.Audita.Modules == nil) != test.wantNil || !reflect.DeepEqual(cfg.Audita.Modules, test.want) {
t.Fatalf("modules = %#v, want %#v (nil=%v)", cfg.Audita.Modules, test.want, test.wantNil)
}
})
}
}
func TestAuditaRejectsRetiredConfigurationFields(t *testing.T) {
for _, field := range []string{"llm_api_key", "base_url", "model", "validation_model", "total_llm_concurrency", "proposal_llm_concurrency", "validation_llm_concurrency", "work_dir_retention", "report"} {
t.Run(field, func(t *testing.T) {
root := writePipelineFixture(t, t.TempDir(), "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\naudita:\n "+field+": retired\n")
if _, err := LoadPipeline(root); err == nil || !strings.Contains(err.Error(), "decode.unknown_field") {
t.Fatalf("error = %v, want unknown field", err)
}
})
}
}
func TestNotariusCredentialOverlayReplacementAndProvenance(t *testing.T) {
const baseKey = "NARRATIO_NOTARIUS_UNUSED_BASE_KEY" const baseKey = "NARRATIO_NOTARIUS_UNUSED_BASE_KEY"
const profileKey = "NARRATIO_NOTARIUS_PROFILE_KEY" const profileKey = "NARRATIO_NOTARIUS_PROFILE_KEY"
if err := os.Unsetenv(baseKey); err != nil { if err := os.Unsetenv(baseKey); err != nil {
@@ -126,24 +202,24 @@ func TestNotariusCredentialProfileReplacementAndProvenance(t *testing.T) {
} }
t.Setenv(profileKey, "synthetic-notarius-profile-key") t.Setenv(profileKey, "synthetic-notarius-profile-key")
for _, credential := range []string{profileKey, "null"} { for _, credential := range []string{"[" + profileKey + "]", "null", "[]"} {
t.Run(credential, func(t *testing.T) { t.Run(credential, func(t *testing.T) {
dir := t.TempDir() dir := t.TempDir()
root := writePipelineFixture(t, dir, "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n llm_api_key: "+baseKey+"\n") root := writePipelineFixture(t, dir, "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n credentials: ["+baseKey+"]\n")
overlay := writePipelineFixture(t, dir, "profiles/testing.yml", "notarius:\n llm_api_key: "+credential+"\n") overlay := writePipelineFixture(t, dir, "overlays/testing.yml", "notarius:\n credentials: "+credential+"\n")
profile := "testing" profile := "testing"
cfg, err := LoadPipelineWithOptions(root, PipelineLoadOptions{Profile: &profile}) cfg, err := LoadPipelineWithOptions(root, PipelineLoadOptions{Overlay: &profile})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if credential == "null" { if credential == "null" || credential == "[]" {
if cfg.Notarius.LLMAPIKey != nil { if len(cfg.Notarius.Credentials) != 0 {
t.Fatal("profile did not remove the base credential") t.Fatal("overlay did not clear base credentials")
} }
return return
} }
if cfg.Notarius.LLMAPIKey == nil || cfg.Notarius.LLMAPIKey.EnvName() != profileKey || !cfg.Notarius.LLMAPIKey.IsResolved() { if len(cfg.Notarius.Credentials) != 1 || cfg.Notarius.Credentials[0].EnvName() != profileKey || !cfg.Notarius.Credentials[0].IsResolved() {
t.Fatal("profile credential was not resolved") t.Fatal("overlay credential was not resolved")
} }
sources, err := EffectivePipelineSources(cfg, ResolvedParty{}) sources, err := EffectivePipelineSources(cfg, ResolvedParty{})
if err != nil { if err != nil {
@@ -151,12 +227,12 @@ func TestNotariusCredentialProfileReplacementAndProvenance(t *testing.T) {
} }
found := false found := false
for _, source := range sources { for _, source := range sources {
if source.Path == "notarius.llm_api_key" { if source.Path == "notarius.credentials" {
found = source.Source == overlay found = source.Source == overlay
} }
} }
if !found { if !found {
t.Fatal("Notarius credential provenance did not identify the selected profile") t.Fatal("Notarius credential provenance did not identify the selected overlay")
} }
}) })
} }
@@ -187,8 +263,8 @@ func TestNotariusConfigProfileComposition(t *testing.T) {
root := writePipelineFixture(t, dir, "pipeline.yml", rootYAML) root := writePipelineFixture(t, dir, "pipeline.yml", rootYAML)
options := PipelineLoadOptions{} options := PipelineLoadOptions{}
if test.overlayName != "" { if test.overlayName != "" {
writePipelineFixture(t, dir, "profiles/"+test.overlayName+".yml", test.overlay) writePipelineFixture(t, dir, "overlays/"+test.overlayName+".yml", test.overlay)
options.Profile = &test.overlayName options.Overlay = &test.overlayName
} }
cfg, err := LoadPipelineWithOptions(root, options) cfg, err := LoadPipelineWithOptions(root, options)
if err != nil { if err != nil {
@@ -205,7 +281,7 @@ func TestNotariusCredentialRootProvenance(t *testing.T) {
const envName = "NARRATIO_NOTARIUS_ROOT_KEY" const envName = "NARRATIO_NOTARIUS_ROOT_KEY"
t.Setenv(envName, "synthetic-notarius-root-key") t.Setenv(envName, "synthetic-notarius-root-key")
dir := t.TempDir() dir := t.TempDir()
root := writePipelineFixture(t, dir, "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n llm_api_key: "+envName+"\n") root := writePipelineFixture(t, dir, "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n credentials: ["+envName+"]\n")
cfg, err := LoadPipeline(root) cfg, err := LoadPipeline(root)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@@ -215,7 +291,7 @@ func TestNotariusCredentialRootProvenance(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
for _, source := range sources { for _, source := range sources {
if source.Path == "notarius.llm_api_key" && source.Source == root { if source.Path == "notarius.credentials" && source.Source == root {
return return
} }
} }
@@ -238,9 +314,9 @@ func TestNotariusCacheControlProfileReplacementAndNullReset(t *testing.T) {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
dir := t.TempDir() dir := t.TempDir()
root := writePipelineFixture(t, dir, "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n resume: false\n chunk_cache: bypass\n") root := writePipelineFixture(t, dir, "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n resume: false\n chunk_cache: bypass\n")
overlay := writePipelineFixture(t, dir, "profiles/testing.yml", test.overlay) overlay := writePipelineFixture(t, dir, "overlays/testing.yml", test.overlay)
profile := "testing" profile := "testing"
cfg, err := LoadPipelineWithOptions(root, PipelineLoadOptions{Profile: &profile}) cfg, err := LoadPipelineWithOptions(root, PipelineLoadOptions{Overlay: &profile})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -282,9 +358,9 @@ whisperx:
transcribe_url: https://transcription.example.test/transcribe transcribe_url: https://transcription.example.test/transcribe
`) `)
writePipelineFixture(t, dir, "artifact.yml", "scriptorium:\n artifacts:\n recap:\n prompt_id: base\n output_path: artifacts/recap.md\n") writePipelineFixture(t, dir, "artifact.yml", "scriptorium:\n artifacts:\n recap:\n prompt_id: base\n output_path: artifacts/recap.md\n")
writePipelineFixture(t, dir, "profiles/testing.yml", "scriptorium:\n artifacts:\n recap:\n prompt_id: testing\n") writePipelineFixture(t, dir, "overlays/testing.yml", "scriptorium:\n artifacts:\n recap:\n prompt_id: testing\n")
profile := "testing" profile := "testing"
cfg, err := LoadPipelineWithOptions(filepath.Join(dir, "pipeline.yml"), PipelineLoadOptions{Profile: &profile}) cfg, err := LoadPipelineWithOptions(filepath.Join(dir, "pipeline.yml"), PipelineLoadOptions{Overlay: &profile})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@@ -176,24 +176,6 @@ func validateAudita(cfg AuditaConfig) error {
return fmt.Errorf("pipeline.audita.modules[%d] must be one of: glossary, homophones, spoken_word, grammar", i) return fmt.Errorf("pipeline.audita.modules[%d] must be one of: glossary, homophones, spoken_word, grammar", i)
} }
} }
if strings.TrimSpace(cfg.BaseURL) != "" {
u, err := url.Parse(cfg.BaseURL)
if err != nil || u.Scheme == "" || u.Host == "" {
if err != nil {
return fmt.Errorf("pipeline.audita.base_url must be a valid URL: %w", err)
}
return fmt.Errorf("pipeline.audita.base_url must be a valid URL")
}
}
if cfg.TotalLLMConcurrency != nil && *cfg.TotalLLMConcurrency <= 0 {
return fmt.Errorf("pipeline.audita.total_llm_concurrency must be > 0")
}
if cfg.ProposalLLMConcurrency != nil && *cfg.ProposalLLMConcurrency <= 0 {
return fmt.Errorf("pipeline.audita.proposal_llm_concurrency must be > 0")
}
if cfg.ValidationLLMConcurrency != nil && *cfg.ValidationLLMConcurrency <= 0 {
return fmt.Errorf("pipeline.audita.validation_llm_concurrency must be > 0")
}
if strings.TrimSpace(cfg.TranscriptDescription) == "" && cfg.TranscriptDescription != "" { if strings.TrimSpace(cfg.TranscriptDescription) == "" && cfg.TranscriptDescription != "" {
return fmt.Errorf("pipeline.audita.transcript_description must be non-empty when provided") return fmt.Errorf("pipeline.audita.transcript_description must be non-empty when provided")
} }
@@ -205,10 +187,5 @@ func validateAudita(cfg AuditaConfig) error {
default: default:
return fmt.Errorf("pipeline.audita.output_schema must be one of: bare-segments, audita-v1") return fmt.Errorf("pipeline.audita.output_schema must be one of: bare-segments, audita-v1")
} }
switch strings.TrimSpace(cfg.WorkDirRetention) {
case "", "always", "auto", "never":
default:
return fmt.Errorf("pipeline.audita.work_dir_retention must be one of: always, auto, never")
}
return nil return nil
} }

View File

@@ -71,13 +71,13 @@ type StageRecord struct {
// EffectiveConfigProvenance records bounded non-secret configuration identity // EffectiveConfigProvenance records bounded non-secret configuration identity
// for one resolved invocation. // for one resolved invocation.
type EffectiveConfigProvenance struct { type EffectiveConfigProvenance struct {
SelectedProfile *SelectedProfileProvenance `json:"selected_profile,omitempty"` SelectedOverlay *SelectedOverlayProvenance `json:"selected_overlay,omitempty"`
EffectiveConfigDigest string `json:"effective_config_digest,omitempty"` EffectiveConfigDigest string `json:"effective_config_digest,omitempty"`
} }
// SelectedProfileProvenance identifies an explicitly or default-selected // SelectedOverlayProvenance identifies an explicitly or default-selected
// pipeline profile without recording profile content. // pipeline overlay without recording overlay content.
type SelectedProfileProvenance struct { type SelectedOverlayProvenance struct {
Name string `json:"name"` Name string `json:"name"`
Source string `json:"source"` Source string `json:"source"`
} }

View File

@@ -34,7 +34,7 @@ func TestLocalStoreCreateSaveLoadRoundTrip(t *testing.T) {
m.S3SessionPrefix = "dnd/campaigns/forsaken/sessions/2026-05-03/" m.S3SessionPrefix = "dnd/campaigns/forsaken/sessions/2026-05-03/"
m.S3RunPrefix = "dnd/campaigns/forsaken/sessions/2026-05-03/runs/20260515T031522Z-a1b2c3d4/" m.S3RunPrefix = "dnd/campaigns/forsaken/sessions/2026-05-03/runs/20260515T031522Z-a1b2c3d4/"
m.EffectiveConfig = &EffectiveConfigProvenance{ m.EffectiveConfig = &EffectiveConfigProvenance{
SelectedProfile: &SelectedProfileProvenance{Name: "production", Source: "default"}, SelectedOverlay: &SelectedOverlayProvenance{Name: "production", Source: "default"},
EffectiveConfigDigest: "001122", EffectiveConfigDigest: "001122",
} }
@@ -57,7 +57,7 @@ func TestLocalStoreCreateSaveLoadRoundTrip(t *testing.T) {
if loaded.RunID != "20260515T031522Z-a1b2c3d4" { if loaded.RunID != "20260515T031522Z-a1b2c3d4" {
t.Fatalf("RunID = %q, want run id", loaded.RunID) t.Fatalf("RunID = %q, want run id", loaded.RunID)
} }
if loaded.EffectiveConfig == nil || loaded.EffectiveConfig.SelectedProfile == nil || loaded.EffectiveConfig.SelectedProfile.Name != "production" || loaded.EffectiveConfig.EffectiveConfigDigest != "001122" { if loaded.EffectiveConfig == nil || loaded.EffectiveConfig.SelectedOverlay == nil || loaded.EffectiveConfig.SelectedOverlay.Name != "production" || loaded.EffectiveConfig.EffectiveConfigDigest != "001122" {
t.Fatalf("effective config provenance = %#v", loaded.EffectiveConfig) t.Fatalf("effective config provenance = %#v", loaded.EffectiveConfig)
} }
stage, ok := loaded.Stages["prepare"] stage, ok := loaded.Stages["prepare"]
@@ -75,6 +75,22 @@ func TestLocalStoreCreateSaveLoadRoundTrip(t *testing.T) {
} }
} }
func TestLocalStoreRejectsUnknownProvenanceFields(t *testing.T) {
for _, tc := range []struct{ name, provenance, field string }{
{"retired selection", `{"selected_profile":{"name":"testing","source":"explicit"}}`, "selected_profile"},
{"unknown provenance", `{"unexpected":true}`, "unexpected"},
{"unknown selection field", `{"selected_overlay":{"name":"testing","source":"explicit","unexpected":true}}`, "unexpected"},
} {
t.Run(tc.name, func(t *testing.T) {
data := `{"schema_version":"narratio.session-manifest.v1","session_id":"2026-05-03","created_at":"2026-05-03T10:00:00Z","updated_at":"2026-05-03T10:00:00Z","effective_config":` + tc.provenance + `,"stages":{}}`
_, err := (&LocalStore{}).LoadReader(context.Background(), strings.NewReader(data))
if err == nil || !strings.Contains(err.Error(), tc.field) {
t.Fatalf("expected rejection identifying %q, got %v", tc.field, err)
}
})
}
}
func TestLocalStorePreservesOptionalArtifactMetadata(t *testing.T) { func TestLocalStorePreservesOptionalArtifactMetadata(t *testing.T) {
store := &LocalStore{} store := &LocalStore{}
ctx := context.Background() ctx := context.Background()

View File

@@ -136,28 +136,26 @@ func (state *analyzeExecutionState) checkpointCollection(
return fmt.Errorf("validate analyze artifact collection: %w", err) return fmt.Errorf("validate analyze artifact collection: %w", err)
} }
candidate := *m
candidate.Stages = make(map[string]*manifest.StageRecord, len(m.Stages))
for name, record := range m.Stages {
candidate.Stages[name] = record
}
analyzeRecord := *m.Stages["analyze"]
analyzeRecord.AnalyzeStateVersion = manifest.AnalyzeStateContractVersion
analyzeRecord.AnalyzeArtifacts = manifest.CloneAnalyzeArtifactCollection(records)
candidate.Stages["analyze"] = &analyzeRecord
manifestPath := artifacts.SessionManifestPathForCampaign( manifestPath := artifacts.SessionManifestPathForCampaign(
state.execution.Paths.WorkspaceRoot, state.execution.Paths.WorkspaceRoot,
m.Campaign, m.Campaign,
m.SessionID, m.SessionID,
) )
if err := state.execution.Env.ManifestStore.Save(ctx, manifestPath, &candidate); err != nil { if err := checkpointStageCollection(
return fmt.Errorf("save session manifest %q: %w", manifestPath, err) ctx,
state.execution.Env.ManifestStore,
manifestPath,
m,
"analyze",
func(record *manifest.StageRecord) error {
record.AnalyzeStateVersion = manifest.AnalyzeStateContractVersion
record.AnalyzeArtifacts = manifest.CloneAnalyzeArtifactCollection(records)
return nil
},
); err != nil {
return err
} }
liveRecord := m.Stages["analyze"] liveRecord := m.Stages["analyze"]
liveRecord.AnalyzeStateVersion = candidate.Stages["analyze"].AnalyzeStateVersion
liveRecord.AnalyzeArtifacts = manifest.CloneAnalyzeArtifactCollection(candidate.Stages["analyze"].AnalyzeArtifacts)
m.UpdatedAt = candidate.UpdatedAt
state.records = manifest.CloneAnalyzeArtifactCollection(liveRecord.AnalyzeArtifacts) state.records = manifest.CloneAnalyzeArtifactCollection(liveRecord.AnalyzeArtifacts)
state.committedRecords = manifest.CloneAnalyzeArtifactCollection(liveRecord.AnalyzeArtifacts) state.committedRecords = manifest.CloneAnalyzeArtifactCollection(liveRecord.AnalyzeArtifacts)
return nil return nil

View File

@@ -0,0 +1,99 @@
package stage
import (
"context"
"fmt"
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
)
// checkpointStageCollection isolates one stage-owned collection update from
// live authority until the existing manifest store reports a successful save.
// Callers own serialization and all stage-specific validation and policy.
func checkpointStageCollection(
ctx context.Context,
store manifest.Store,
path string,
live *manifest.Manifest,
stageName string,
update func(*manifest.StageRecord) error,
) error {
if live == nil {
return fmt.Errorf("session manifest is required")
}
if store == nil {
return fmt.Errorf("manifest store is required")
}
if update == nil {
return fmt.Errorf("checkpoint update is required")
}
candidate := cloneManifestForCheckpoint(live)
if candidate.Stages == nil {
candidate.Stages = make(map[string]*manifest.StageRecord)
}
target, exists := candidate.Stages[stageName]
if !exists {
target = &manifest.StageRecord{}
candidate.Stages[stageName] = target
} else if target == nil {
// Retain the invalid nil entry for Store.Save to reject rather than
// silently repairing manifest state. The detached record only gives the
// typed update a safe value to operate on before that validation.
target = &manifest.StageRecord{}
}
if err := update(target); err != nil {
return fmt.Errorf("update stage %q checkpoint: %w", stageName, err)
}
if err := store.Save(ctx, path, candidate); err != nil {
return fmt.Errorf("save session manifest %q: %w", path, err)
}
savedRecord := cloneStageRecordForCheckpoint(candidate.Stages[stageName])
if savedRecord == nil {
return fmt.Errorf("saved stage %q checkpoint record is nil", stageName)
}
if live.Stages != nil {
if current := live.Stages[stageName]; current != nil {
*current = *savedRecord
} else {
live.Stages[stageName] = savedRecord
}
} else {
live.Stages = map[string]*manifest.StageRecord{stageName: savedRecord}
}
live.UpdatedAt = candidate.UpdatedAt
return nil
}
// cloneManifestForCheckpoint copies the bounded mutable state touched by the
// two checkpoint callbacks or by manifest.LocalStore.Save. Metadata maps and
// other pointer fields remain shared read-only because neither boundary mutates
// them.
func cloneManifestForCheckpoint(source *manifest.Manifest) *manifest.Manifest {
clone := *source
clone.Inputs = append([]manifest.InputRecord(nil), source.Inputs...)
clone.Artifacts = append([]manifest.ArtifactRecord(nil), source.Artifacts...)
if source.Stages == nil {
clone.Stages = nil
return &clone
}
clone.Stages = make(map[string]*manifest.StageRecord, len(source.Stages))
for name, sourceRecord := range source.Stages {
clone.Stages[name] = cloneStageRecordForCheckpoint(sourceRecord)
}
return &clone
}
func cloneStageRecordForCheckpoint(source *manifest.StageRecord) *manifest.StageRecord {
if source == nil {
return nil
}
clone := *source
clone.Outputs = append([]manifest.ArtifactRecord(nil), source.Outputs...)
clone.Logs = append([]string(nil), source.Logs...)
clone.GeneratedConfigs = append([]string(nil), source.GeneratedConfigs...)
clone.TranscribeSpeakers = manifest.CloneTranscribeSpeakerCollection(source.TranscribeSpeakers)
clone.AnalyzeArtifacts = manifest.CloneAnalyzeArtifactCollection(source.AnalyzeArtifacts)
return &clone
}

View File

@@ -0,0 +1,327 @@
package stage
import (
"context"
"encoding/json"
"errors"
"path/filepath"
"reflect"
"slices"
"strings"
"testing"
"time"
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
)
func TestCheckpointStageCollectionSavesThenPromotesTarget(t *testing.T) {
now := time.Date(2026, 9, 22, 12, 0, 0, 0, time.UTC)
live := checkpointTestManifest(now)
originalAnalyze := live.Stages["analyze"]
originalTranscribe := live.Stages["transcribe"]
originalMerge := live.Stages["merge"]
replacement := map[string]manifest.AnalyzeArtifactRecord{
"result": checkpointAnalyzeRecord(now.Add(time.Minute), []string{"zeta", "alpha"}),
}
path := filepath.Join(t.TempDir(), "manifest.json")
base := &manifest.LocalStore{}
store := &checkpointBoundaryStore{
Store: base,
BeforeSave: func(candidate *manifest.Manifest) {
if live.Stages["analyze"] != originalAnalyze || len(originalAnalyze.AnalyzeArtifacts) != 1 {
t.Fatal("live analyze authority changed before save")
}
if candidate.Stages["analyze"] == originalAnalyze || candidate.Stages["transcribe"] == originalTranscribe {
t.Fatal("checkpoint candidate shares stage records with live manifest")
}
},
}
err := checkpointStageCollection(context.Background(), store, path, live, "analyze", func(record *manifest.StageRecord) error {
record.AnalyzeStateVersion = manifest.AnalyzeStateContractVersion
record.AnalyzeArtifacts = replacement
return nil
})
if err != nil {
t.Fatalf("checkpointStageCollection() error = %v", err)
}
if store.Calls != 1 {
t.Fatalf("Save calls = %d, want 1", store.Calls)
}
if live.Stages["analyze"] != originalAnalyze {
t.Fatal("existing target record pointer identity changed")
}
if live.Stages["transcribe"] != originalTranscribe || live.Stages["merge"] != originalMerge {
t.Fatal("unrelated stage record identity changed")
}
if originalAnalyze.Status != manifest.StatusRunning || originalAnalyze.Outputs[0].LocalPath != "artifacts/aggregate.md" {
t.Fatalf("aggregate analyze data changed = %#v", originalAnalyze)
}
if got := originalAnalyze.AnalyzeArtifacts["result"].Dependencies; !slices.Equal(got, []string{"alpha", "zeta"}) {
t.Fatalf("promoted dependencies = %#v, want normalized saved state", got)
}
if !live.UpdatedAt.After(now) {
t.Fatalf("live UpdatedAt = %v, want save timestamp after %v", live.UpdatedAt, now)
}
durable, err := base.Load(context.Background(), path)
if err != nil {
t.Fatalf("Load() error = %v", err)
}
if !reflect.DeepEqual(durable.Stages["analyze"], live.Stages["analyze"]) {
t.Fatalf("durable analyze = %#v, live = %#v", durable.Stages["analyze"], live.Stages["analyze"])
}
if !reflect.DeepEqual(durable.Stages["transcribe"], originalTranscribe) || !reflect.DeepEqual(durable.Stages["merge"], originalMerge) {
t.Fatal("unrelated durable stage data changed")
}
changed := replacement["result"]
changed.Status = manifest.AnalyzeArtifactFailed
changed.Dependencies[0] = "changed"
replacement["result"] = changed
if got := live.Stages["analyze"].AnalyzeArtifacts["result"]; got.Status != manifest.AnalyzeArtifactMissing || got.Dependencies[0] != "alpha" {
t.Fatalf("caller edits mutated committed record = %#v", got)
}
}
func TestCheckpointStageCollectionFailureLeavesLiveAuthorityUnchanged(t *testing.T) {
t.Run("update", func(t *testing.T) {
live := checkpointTestManifest(time.Now().UTC())
before := checkpointManifestJSON(t, live)
cause := errors.New("update failed")
store := &checkpointBoundaryStore{Store: &manifest.LocalStore{}}
err := checkpointStageCollection(context.Background(), store, filepath.Join(t.TempDir(), "manifest.json"), live, "analyze", func(record *manifest.StageRecord) error {
record.AnalyzeArtifacts = map[string]manifest.AnalyzeArtifactRecord{}
return cause
})
if !errors.Is(err, cause) {
t.Fatalf("error = %v, want update cause", err)
}
if store.Calls != 0 {
t.Fatalf("Save calls = %d, want 0", store.Calls)
}
assertCheckpointManifestJSON(t, live, before)
})
t.Run("validation", func(t *testing.T) {
live := checkpointTestManifest(time.Now().UTC())
before := checkpointManifestJSON(t, live)
store := &checkpointBoundaryStore{Store: &manifest.LocalStore{}}
path := filepath.Join(t.TempDir(), "manifest.json")
err := checkpointStageCollection(context.Background(), store, path, live, "analyze", func(record *manifest.StageRecord) error {
record.Name = "wrong-stage"
return nil
})
if err == nil {
t.Fatal("error = nil, want manifest validation failure")
}
if store.Calls != 1 {
t.Fatalf("Save calls = %d, want 1", store.Calls)
}
assertCheckpointManifestJSON(t, live, before)
})
t.Run("save after candidate mutation", func(t *testing.T) {
now := time.Date(2026, 9, 22, 12, 0, 0, 0, time.UTC)
live := checkpointTestManifest(now)
analyze := live.Stages["analyze"].AnalyzeArtifacts["result"]
analyze.Dependencies = []string{"zeta", "alpha"}
live.Stages["analyze"].AnalyzeArtifacts["result"] = analyze
before := checkpointManifestJSON(t, live)
cause := errors.New("save failed after mutation")
store := &checkpointBoundaryStore{Store: &manifest.LocalStore{}, ReturnErr: cause}
path := filepath.Join(t.TempDir(), "manifest.json")
replacement := checkpointTranscribeCollection("bob", "run-2")
err := checkpointStageCollection(context.Background(), store, path, live, "transcribe", func(record *manifest.StageRecord) error {
record.TranscribeStateVersion = manifest.TranscribeStateContractVersion
record.TranscribeSpeakers = replacement
return nil
})
if !errors.Is(err, cause) {
t.Fatalf("error = %v, want save cause", err)
}
if !strings.Contains(err.Error(), path) {
t.Fatalf("error = %q, want manifest path context", err)
}
if store.Calls != 1 || store.SavedCandidate == nil {
t.Fatalf("Save calls/candidate = %d/%p, want one observed candidate", store.Calls, store.SavedCandidate)
}
if !store.SavedCandidate.UpdatedAt.After(now) {
t.Fatalf("candidate UpdatedAt = %v, want Store.Save mutation", store.SavedCandidate.UpdatedAt)
}
if got := store.SavedCandidate.Stages["analyze"].AnalyzeArtifacts["result"].Dependencies; !slices.Equal(got, []string{"alpha", "zeta"}) {
t.Fatalf("candidate dependencies = %#v, want save-time normalization", got)
}
if got := live.Stages["analyze"].AnalyzeArtifacts["result"].Dependencies; !slices.Equal(got, []string{"zeta", "alpha"}) {
t.Fatalf("live dependencies = %#v, save-time normalization leaked", got)
}
assertCheckpointManifestJSON(t, live, before)
changed := replacement["bob"]
changed.AudioPath = "audio/changed.flac"
replacement["bob"] = changed
if got := live.Stages["transcribe"].TranscribeSpeakers; len(got) != 1 || got["alice"].AudioPath != "audio/alice.flac" {
t.Fatalf("failed save changed live transcribe collection = %#v", got)
}
})
}
func TestCheckpointStageCollectionMissingTargetAppearsOnlyAfterSuccess(t *testing.T) {
now := time.Date(2026, 9, 22, 12, 0, 0, 0, time.UTC)
live := checkpointTestManifest(now)
delete(live.Stages, "transcribe")
path := filepath.Join(t.TempDir(), "manifest.json")
cause := errors.New("save failed")
failing := &checkpointBoundaryStore{Store: &manifest.LocalStore{}, ReturnErr: cause}
update := func(record *manifest.StageRecord) error {
record.Name = "transcribe"
record.Status = manifest.StatusRunning
record.CreatedAt = now
record.UpdatedAt = now
record.TranscribeStateVersion = manifest.TranscribeStateContractVersion
record.TranscribeSpeakers = checkpointTranscribeCollection("alice", "run-1")
return nil
}
if err := checkpointStageCollection(context.Background(), failing, path, live, "transcribe", update); !errors.Is(err, cause) {
t.Fatalf("failed checkpoint error = %v, want %v", err, cause)
}
if _, exists := live.Stages["transcribe"]; exists {
t.Fatal("missing live target was allocated after failed save")
}
successPath := filepath.Join(t.TempDir(), "manifest.json")
if err := checkpointStageCollection(context.Background(), &manifest.LocalStore{}, successPath, live, "transcribe", update); err != nil {
t.Fatalf("successful checkpoint error = %v", err)
}
created := live.Stages["transcribe"]
if created == nil || created.Name != "transcribe" || created.Status != manifest.StatusRunning {
t.Fatalf("promoted missing target = %#v", created)
}
durable, err := (&manifest.LocalStore{}).Load(context.Background(), successPath)
if err != nil {
t.Fatalf("Load() error = %v", err)
}
if !reflect.DeepEqual(durable.Stages["transcribe"], created) {
t.Fatalf("durable target = %#v, live = %#v", durable.Stages["transcribe"], created)
}
}
func TestCheckpointStageCollectionPreservesContextAndRequiredInputs(t *testing.T) {
now := time.Now().UTC()
live := checkpointTestManifest(now)
path := filepath.Join(t.TempDir(), "manifest.json")
update := func(*manifest.StageRecord) error { return nil }
store := &checkpointBoundaryStore{Store: &manifest.LocalStore{}}
ctx, cancel := context.WithCancel(context.Background())
cancel()
before := checkpointManifestJSON(t, live)
err := checkpointStageCollection(ctx, store, path, live, "analyze", update)
if !errors.Is(err, context.Canceled) {
t.Fatalf("canceled error = %v, want context.Canceled", err)
}
if !strings.Contains(err.Error(), path) {
t.Fatalf("canceled error = %q, want manifest path context", err)
}
assertCheckpointManifestJSON(t, live, before)
if err := checkpointStageCollection(context.Background(), store, path, nil, "analyze", update); err == nil {
t.Fatal("nil live manifest error = nil")
}
if err := checkpointStageCollection(context.Background(), nil, path, live, "analyze", update); err == nil {
t.Fatal("nil store error = nil")
}
if err := checkpointStageCollection(context.Background(), store, path, live, "analyze", nil); err == nil {
t.Fatal("nil update error = nil")
}
}
type checkpointBoundaryStore struct {
manifest.Store
Calls int
BeforeSave func(*manifest.Manifest)
ReturnErr error
SavedCandidate *manifest.Manifest
}
func (store *checkpointBoundaryStore) Save(ctx context.Context, path string, candidate *manifest.Manifest) error {
store.Calls++
if store.BeforeSave != nil {
store.BeforeSave(candidate)
}
if err := store.Store.Save(ctx, path, candidate); err != nil {
return err
}
store.SavedCandidate = candidate
return store.ReturnErr
}
func checkpointTestManifest(now time.Time) *manifest.Manifest {
live := manifest.New("session-1", now)
live.Campaign = "campaign-1"
live.RunID = "run-1"
live.Inputs = []manifest.InputRecord{{Kind: "audio", Path: "audio/alice.flac"}}
live.Artifacts = []manifest.ArtifactRecord{{Kind: "existing", LocalPath: "artifacts/existing.json"}}
live.Stages["analyze"] = &manifest.StageRecord{
Name: "analyze", Status: manifest.StatusRunning, CreatedAt: now, UpdatedAt: now,
Outputs: []manifest.ArtifactRecord{{Kind: "analysis", LocalPath: "artifacts/aggregate.md"}},
Logs: []string{"runs/run-1/analyze.log"},
GeneratedConfigs: []string{"runs/run-1/analyze.yml"},
Metadata: map[string]any{"shared_read_only": true},
AnalyzeStateVersion: manifest.AnalyzeStateContractVersion,
AnalyzeArtifacts: map[string]manifest.AnalyzeArtifactRecord{
"result": checkpointAnalyzeRecord(now, []string{"old_dependency"}),
},
}
live.Stages["transcribe"] = &manifest.StageRecord{
Name: "transcribe", Status: manifest.StatusFailed, CreatedAt: now, UpdatedAt: now,
TranscribeStateVersion: manifest.TranscribeStateContractVersion,
TranscribeSpeakers: checkpointTranscribeCollection("alice", "run-1"),
}
live.Stages["merge"] = &manifest.StageRecord{
Name: "merge", Status: manifest.StatusSucceeded, CreatedAt: now, UpdatedAt: now,
Outputs: []manifest.ArtifactRecord{{Kind: "transcript_base", LocalPath: "transcripts/base.json"}},
}
return live
}
func checkpointAnalyzeRecord(now time.Time, dependencies []string) manifest.AnalyzeArtifactRecord {
return manifest.AnalyzeArtifactRecord{
Key: "result", Status: manifest.AnalyzeArtifactMissing,
Dependencies: dependencies, ProducerRunID: "run-1", UpdatedAt: now,
}
}
func checkpointTranscribeCollection(speaker, runID string) map[string]manifest.TranscribeSpeakerRecord {
return map[string]manifest.TranscribeSpeakerRecord{
speaker: {
FingerprintVersion: manifest.TranscribeFingerprintContractVersion,
Fingerprint: strings.Repeat("b", 64),
AudioPath: "audio/" + speaker + ".flac",
AudioSHA256: strings.Repeat("a", 64),
AudioSize: 0,
Output: manifest.ArtifactRecord{
Kind: "transcript_raw", LocalPath: "transcripts/raw/" + speaker + ".json",
Checksum: strings.Repeat("c", 64), ProducerRunID: runID,
},
OutputSize: 1, ProducerRunID: runID,
},
}
}
func checkpointManifestJSON(t *testing.T, value *manifest.Manifest) []byte {
t.Helper()
data, err := json.Marshal(value)
if err != nil {
t.Fatalf("Marshal() error = %v", err)
}
return data
}
func assertCheckpointManifestJSON(t *testing.T, value *manifest.Manifest, want []byte) {
t.Helper()
if got := checkpointManifestJSON(t, value); !slices.Equal(got, want) {
t.Fatalf("live manifest changed on failure\ngot: %s\nwant: %s", got, want)
}
}

View File

@@ -146,7 +146,7 @@ func (extractStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (re
chunkCache = "refresh" chunkCache = "refresh"
} }
request := notarius.RunRequest{ request := notarius.RunRequest{
Binary: resolvedBinary, LLMAPIKey: notariusConfig.LLMAPIKey, ConfigProfile: notariusConfig.ConfigProfile, Binary: resolvedBinary, Credentials: notariusConfig.Credentials, ConfigProfile: notariusConfig.ConfigProfile,
ConfigPath: configPath, PipelineID: notariusConfig.PipelineID, ConfigPath: configPath, PipelineID: notariusConfig.PipelineID,
InputPath: inputPath, OutputRoot: outputRoot, WorkingDirectory: workingDirectory, InputPath: inputPath, OutputRoot: outputRoot, WorkingDirectory: workingDirectory,
ReceiptPath: receiptPath, LogPath: logPath, Timeout: timeout, Resume: resume, ChunkCache: chunkCache, References: referenceBindings, ReceiptPath: receiptPath, LogPath: logPath, Timeout: timeout, Resume: resume, ChunkCache: chunkCache, References: referenceBindings,

View File

@@ -61,7 +61,7 @@ func TestExtractStageResolvesManifestInputAndBuildsExactRequest(t *testing.T) {
transcribe_url: https://transcription.example.test/transcribe transcribe_url: https://transcription.example.test/transcribe
notarius: notarius:
enabled: false enabled: false
llm_api_key: NARRATIO_EXTRACT_NOTARIUS_KEY credentials: [NARRATIO_EXTRACT_NOTARIUS_KEY]
`), 0o644); err != nil { `), 0o644); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -71,7 +71,7 @@ notarius:
} }
env, m, fake := setupExtractEnv(t) env, m, fake := setupExtractEnv(t)
env.Config.Pipeline.Notarius.LLMAPIKey = loadedPipeline.Notarius.LLMAPIKey env.Config.Pipeline.Notarius.Credentials = loadedPipeline.Notarius.Credentials
configProfile := "inexpensive" configProfile := "inexpensive"
env.Config.Pipeline.Notarius.ConfigProfile = &configProfile env.Config.Pipeline.Notarius.ConfigProfile = &configProfile
result, err := (extractStage{}).Run(context.Background(), env, m) result, err := (extractStage{}).Run(context.Background(), env, m)
@@ -103,7 +103,7 @@ notarius:
if req.Resume || req.ChunkCache != "" { if req.Resume || req.ChunkCache != "" {
t.Fatalf("default cache controls = resume %v, mode %q", req.Resume, req.ChunkCache) t.Fatalf("default cache controls = resume %v, mode %q", req.Resume, req.ChunkCache)
} }
if req.LLMAPIKey != loadedPipeline.Notarius.LLMAPIKey || req.LLMAPIKey.EnvName() != credentialName || !req.LLMAPIKey.IsResolved() { if len(req.Credentials) != 1 || req.Credentials[0].EnvName() != credentialName || !req.Credentials[0].IsResolved() {
t.Fatal("request did not retain the loaded Notarius credential reference") t.Fatal("request did not retain the loaded Notarius credential reference")
} }
if req.ConfigProfile == nil || *req.ConfigProfile != configProfile { if req.ConfigProfile == nil || *req.ConfigProfile != configProfile {

View File

@@ -67,43 +67,28 @@ func (polishStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*St
if err != nil { if err != nil {
return nil, fmt.Errorf("polish: resolve run-local processed transcript path: %w", err) return nil, fmt.Errorf("polish: resolve run-local processed transcript path: %w", err)
} }
canonicalReportPath := filepath.Join(paths.ArtifactsDir, "audita.report.json")
reportPath := canonicalReportPath
if runLayout.Enabled {
reportPath, err = runLocalPathForCanonical(runLayout, paths, canonicalReportPath)
if err != nil {
return nil, fmt.Errorf("polish: resolve run-local report path: %w", err)
}
}
workDir := filepath.Join(paths.ArtifactsDir, "audita-work")
stdoutPath := filepath.Join(paths.LogsDir, "audita.stdout.log") stdoutPath := filepath.Join(paths.LogsDir, "audita.stdout.log")
stderrPath := filepath.Join(paths.LogsDir, "audita.stderr.log") stderrPath := filepath.Join(paths.LogsDir, "audita.stderr.log")
generatedConfigPath := filepath.Join(paths.ConfigDir, "audita.generated.yml") generatedConfigPath := filepath.Join(paths.ConfigDir, "audita.generated.yml")
if runLayout.Enabled { if runLayout.Enabled {
workDir = filepath.Join(runLayout.ScratchDir, "audita-work")
stdoutPath = filepath.Join(runLayout.LogsDir, "audita.stdout.log") stdoutPath = filepath.Join(runLayout.LogsDir, "audita.stdout.log")
stderrPath = filepath.Join(runLayout.LogsDir, "audita.stderr.log") stderrPath = filepath.Join(runLayout.LogsDir, "audita.stderr.log")
generatedConfigPath = filepath.Join(runLayout.ConfigDir, "audita.generated.yml") generatedConfigPath = filepath.Join(runLayout.ConfigDir, "audita.generated.yml")
} }
reportEnabled := env.Config.Pipeline.Audita.Report != nil && *env.Config.Pipeline.Audita.Report
req := audita.PolishRequest{ req := audita.PolishRequest{
GeneratedConfigPath: generatedConfigPath, GeneratedConfigPath: generatedConfigPath,
MergedTranscriptPath: mergedPath, MergedTranscriptPath: mergedPath,
OutputProcessedPath: processedPath, OutputProcessedPath: processedPath,
GlossaryPath: glossaryPath, GlossaryPath: glossaryPath,
ReportPath: "",
WorkDir: workDir,
StdoutLogPath: stdoutPath, StdoutLogPath: stdoutPath,
StderrLogPath: stderrPath, StderrLogPath: stderrPath,
} }
if reportEnabled {
req.ReportPath = reportPath
}
res, err := env.Audita.Run(ctx, req) res, err := env.Audita.Run(ctx, req)
if err != nil { if err != nil {
return nil, fmt.Errorf("polish: audita polish failed: %w", err) return nil, fmt.Errorf("polish: audita polish failed (output_dir=%q, stdout_log=%q, stderr_log=%q): %w",
filepath.Dir(processedPath), stdoutPath, stderrPath, err)
} }
finalProcessedPath, err := authoritativeOutputPath(processedPath, res.ProcessedTranscriptPath) finalProcessedPath, err := authoritativeOutputPath(processedPath, res.ProcessedTranscriptPath)
@@ -113,15 +98,26 @@ func (polishStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*St
if err := validateProcessedTranscriptOutput(finalProcessedPath); err != nil { if err := validateProcessedTranscriptOutput(finalProcessedPath); err != nil {
return nil, fmt.Errorf("polish: processed transcript %q invalid: %w", finalProcessedPath, err) return nil, fmt.Errorf("polish: processed transcript %q invalid: %w", finalProcessedPath, err)
} }
reportPaths := make([]string, 0, 3)
finalReportPath, err := authoritativeOutputPath(req.ReportPath, res.ReportPath) reportMetadata := map[string]string{}
if err != nil { for _, report := range []struct{ name, returned string }{
return nil, fmt.Errorf("polish: %w", err) {"errors.yml", res.Reports.ErrorsPath},
} {"recoveries.yml", res.Reports.RecoveriesPath},
if reportEnabled { {"report.md", res.Reports.OverviewPath},
if err := validateTranscriptJSONFile(finalReportPath); err != nil { } {
return nil, fmt.Errorf("polish: report %q invalid: %w", finalReportPath, err) if report.returned == "" {
continue
} }
expected := filepath.Join(filepath.Dir(processedPath), report.name)
path, err := authoritativeOutputPath(expected, report.returned)
if err != nil {
return nil, fmt.Errorf("polish: report %s: %w", report.name, err)
}
if err := requireRegularReadableFile(path, "audita report"); err != nil {
return nil, fmt.Errorf("polish: %w", err)
}
reportPaths = append(reportPaths, path)
reportMetadata[report.name] = path
} }
materializedProcessed, err := materializeRunLocalOutput(env.ArtifactStore, finalProcessedPath, canonicalProcessedPath, artifacts.Ref{ materializedProcessed, err := materializeRunLocalOutput(env.ArtifactStore, finalProcessedPath, canonicalProcessedPath, artifacts.Ref{
@@ -133,39 +129,6 @@ func (polishStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*St
return nil, fmt.Errorf("polish: materialize canonical polished transcript: %w", err) return nil, fmt.Errorf("polish: materialize canonical polished transcript: %w", err)
} }
outputs := []artifacts.Ref{materializedProcessed} outputs := []artifacts.Ref{materializedProcessed}
if reportEnabled {
materializedReport, err := materializeRunLocalOutput(env.ArtifactStore, finalReportPath, canonicalReportPath, artifacts.Ref{
Kind: "audita_report",
Category: "artifacts",
SessionID: sessionID,
})
if err != nil {
return nil, fmt.Errorf("polish: materialize canonical report: %w", err)
}
outputs = append(outputs, materializedReport)
}
var validationConcurrency any
if env.Config.Pipeline.Audita.ValidationLLMConcurrency != nil {
validationConcurrency = *env.Config.Pipeline.Audita.ValidationLLMConcurrency
}
var totalLLMConcurrency any
if env.Config.Pipeline.Audita.TotalLLMConcurrency != nil {
totalLLMConcurrency = *env.Config.Pipeline.Audita.TotalLLMConcurrency
}
var proposalLLMConcurrency any
if env.Config.Pipeline.Audita.ProposalLLMConcurrency != nil {
proposalLLMConcurrency = *env.Config.Pipeline.Audita.ProposalLLMConcurrency
}
reportCanonicalPath := ""
if reportEnabled {
reportCanonicalPath = canonicalReportPath
}
credentialReference := ""
if env.Config.Pipeline.Audita.LLMAPIKey != nil {
credentialReference = env.Config.Pipeline.Audita.LLMAPIKey.EnvName()
}
meta := map[string]any{ meta := map[string]any{
"stage": "polish", "stage": "polish",
"merged_transcript_path": mergedPath, "merged_transcript_path": mergedPath,
@@ -173,22 +136,13 @@ func (polishStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*St
"glossary_path": glossaryPath, "glossary_path": glossaryPath,
"run_output_path": finalProcessedPath, "run_output_path": finalProcessedPath,
"output_path": canonicalProcessedPath, "output_path": canonicalProcessedPath,
"run_report_path": finalReportPath, "modules": append(env.Config.Pipeline.Audita.Modules[:0:0], env.Config.Pipeline.Audita.Modules...),
"report_path": reportCanonicalPath, "overlay": env.Config.Pipeline.Audita.Overlay,
"audita_work_dir": workDir, "proposal_profile": env.Config.Pipeline.Audita.ProposalProfile,
"report_enabled": reportEnabled, "validation_profile": env.Config.Pipeline.Audita.ValidationProfile,
"modules": append([]string(nil), env.Config.Pipeline.Audita.Modules...),
"base_url": env.Config.Pipeline.Audita.BaseURL,
"model": env.Config.Pipeline.Audita.Model,
"transcript_description": env.Config.Pipeline.Audita.TranscriptDescription, "transcript_description": env.Config.Pipeline.Audita.TranscriptDescription,
"config_path": env.Config.Pipeline.Audita.ConfigPath, "config_path": env.Config.Pipeline.Audita.ConfigPath,
"output_schema": env.Config.Pipeline.Audita.OutputSchema, "output_schema": env.Config.Pipeline.Audita.OutputSchema,
"work_dir_retention": env.Config.Pipeline.Audita.WorkDirRetention,
"validation_model": env.Config.Pipeline.Audita.ValidationModel,
"total_llm_concurrency": totalLLMConcurrency,
"proposal_llm_concurrency": proposalLLMConcurrency,
"validation_llm_concurrency": validationConcurrency,
"llm_api_key": credentialReference,
"timeout": env.Config.Pipeline.Audita.Timeout, "timeout": env.Config.Pipeline.Audita.Timeout,
"binary": env.Config.Pipeline.Audita.Binary, "binary": env.Config.Pipeline.Audita.Binary,
"generated_config_path": generatedConfigPath, "generated_config_path": generatedConfigPath,
@@ -198,27 +152,18 @@ func (polishStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*St
"adapter_exit_code": res.ExitCode, "adapter_exit_code": res.ExitCode,
"adapter_invoked_binary": res.InvokedBinary, "adapter_invoked_binary": res.InvokedBinary,
"adapter_processed_output_path": res.ProcessedTranscriptPath, "adapter_processed_output_path": res.ProcessedTranscriptPath,
"adapter_report_path": res.ReportPath,
"adapter_generated_config_path": res.GeneratedConfigPath, "adapter_generated_config_path": res.GeneratedConfigPath,
"adapter_work_dir": res.WorkDir,
"adapter_stdout_log_path": res.StdoutLogPath, "adapter_stdout_log_path": res.StdoutLogPath,
"adapter_stderr_log_path": res.StderrLogPath, "adapter_stderr_log_path": res.StderrLogPath,
"credential_env_var": credentialReference, "report_paths": reportMetadata,
"credential_present": false,
} }
if res.Metadata != nil { if res.Metadata != nil {
meta["adapter_metadata"] = res.Metadata meta["adapter_metadata"] = res.Metadata
if value, ok := res.Metadata["credential_present"]; ok {
meta["credential_present"] = value
}
if value, ok := res.Metadata["credential_env_var"]; ok {
meta["credential_env_var"] = value
}
} }
return &StageResult{ return &StageResult{
Outputs: outputs, Outputs: outputs,
Logs: []string{stdoutPath, stderrPath}, Logs: append([]string{stdoutPath, stderrPath}, reportPaths...),
GeneratedConfigs: []string{generatedConfigPath}, GeneratedConfigs: []string{generatedConfigPath},
Metadata: meta, Metadata: meta,
}, nil }, nil

View File

@@ -3,17 +3,26 @@ package stage
import ( import (
"context" "context"
"errors" "errors"
"os"
"path/filepath" "path/filepath"
"slices"
"strings" "strings"
"testing" "testing"
"time" "time"
configkit "gitea.maximumdirect.net/eric/ConfigKit"
"gitea.maximumdirect.net/eric/narratio/internal/adapters/audita" "gitea.maximumdirect.net/eric/narratio/internal/adapters/audita"
"gitea.maximumdirect.net/eric/narratio/internal/artifacts" "gitea.maximumdirect.net/eric/narratio/internal/artifacts"
"gitea.maximumdirect.net/eric/narratio/internal/config" "gitea.maximumdirect.net/eric/narratio/internal/config"
"gitea.maximumdirect.net/eric/narratio/internal/manifest" "gitea.maximumdirect.net/eric/narratio/internal/manifest"
) )
type polishRunnerFunc func(context.Context, audita.PolishRequest) (audita.PolishResult, error)
func (run polishRunnerFunc) Run(ctx context.Context, req audita.PolishRequest) (audita.PolishResult, error) {
return run(ctx, req)
}
func TestPolishStagePolishesMergedTranscriptAndRecordsMetadata(t *testing.T) { func TestPolishStagePolishesMergedTranscriptAndRecordsMetadata(t *testing.T) {
env, m := setupPolishEnv(t) env, m := setupPolishEnv(t)
paths := sessionPathsForEnv(env, m.SessionID) paths := sessionPathsForEnv(env, m.SessionID)
@@ -43,20 +52,20 @@ func TestPolishStagePolishesMergedTranscriptAndRecordsMetadata(t *testing.T) {
if req.GlossaryPath != filepath.Join(paths.InputsDir, "glossary.yml") { if req.GlossaryPath != filepath.Join(paths.InputsDir, "glossary.yml") {
t.Fatalf("glossary path = %q", req.GlossaryPath) t.Fatalf("glossary path = %q", req.GlossaryPath)
} }
if req.WorkDir != filepath.Join(paths.ArtifactsDir, "audita-work") { if len(result.Outputs) != 1 {
t.Fatalf("work dir = %q", req.WorkDir) t.Fatalf("outputs len = %d, want 1", len(result.Outputs))
}
if len(result.Outputs) != 2 {
t.Fatalf("outputs len = %d, want 2", len(result.Outputs))
} }
if result.Outputs[0].Kind != "transcript_polished" { if result.Outputs[0].Kind != "transcript_polished" {
t.Fatalf("output[0] kind = %q, want transcript_polished", result.Outputs[0].Kind) t.Fatalf("output[0] kind = %q, want transcript_polished", result.Outputs[0].Kind)
} }
if result.Outputs[1].Kind != "audita_report" { if len(result.Logs) != 5 {
t.Fatalf("output[1] kind = %q, want audita_report", result.Outputs[1].Kind) t.Fatalf("logs = %#v, want stdout, stderr, and three reports", result.Logs)
} }
if len(result.Logs) != 2 { for _, name := range []string{"errors.yml", "recoveries.yml", "report.md"} {
t.Fatalf("logs = %#v, want 2", result.Logs) path := filepath.Join(filepath.Dir(req.OutputProcessedPath), name)
if !slices.Contains(result.Logs, path) {
t.Fatalf("report %q missing from diagnostics: %#v", path, result.Logs)
}
} }
if len(result.GeneratedConfigs) != 1 { if len(result.GeneratedConfigs) != 1 {
t.Fatalf("generated configs = %#v, want 1", result.GeneratedConfigs) t.Fatalf("generated configs = %#v, want 1", result.GeneratedConfigs)
@@ -65,21 +74,12 @@ func TestPolishStagePolishesMergedTranscriptAndRecordsMetadata(t *testing.T) {
if result.Metadata["stage"] != "polish" { if result.Metadata["stage"] != "polish" {
t.Fatalf("metadata stage = %#v, want polish", result.Metadata["stage"]) t.Fatalf("metadata stage = %#v, want polish", result.Metadata["stage"])
} }
if result.Metadata["report_enabled"] != true {
t.Fatalf("metadata report_enabled = %#v, want true", result.Metadata["report_enabled"])
}
if result.Metadata["audita_work_dir"] != filepath.Join(paths.ArtifactsDir, "audita-work") {
t.Fatalf("metadata audita_work_dir = %#v", result.Metadata["audita_work_dir"])
}
if result.Metadata["total_llm_concurrency"] != 3 {
t.Fatalf("metadata total_llm_concurrency = %#v, want 3", result.Metadata["total_llm_concurrency"])
}
if result.Metadata["proposal_llm_concurrency"] != 2 {
t.Fatalf("metadata proposal_llm_concurrency = %#v, want 2", result.Metadata["proposal_llm_concurrency"])
}
if result.Metadata["output_schema"] != "audita-v1" { if result.Metadata["output_schema"] != "audita-v1" {
t.Fatalf("metadata output_schema = %#v, want audita-v1", result.Metadata["output_schema"]) t.Fatalf("metadata output_schema = %#v, want audita-v1", result.Metadata["output_schema"])
} }
if _, err := os.Stat(filepath.Join(paths.ArtifactsDir, "audita.report.json")); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("legacy report destination exists: %v", err)
}
} }
func TestPolishStageRejectsIncidentalMergedTranscriptPath(t *testing.T) { func TestPolishStageRejectsIncidentalMergedTranscriptPath(t *testing.T) {
@@ -166,6 +166,58 @@ func TestPolishStageFailsWhenAdapterFails(t *testing.T) {
} }
} }
func TestPolishStageDoesNotPromoteTranscriptAfterAdapterFailure(t *testing.T) {
env, m := setupPolishEnv(t)
env.Config.Session.Campaign = "sample-campaign"
m.Campaign = "sample-campaign"
m.RunID = "20260518T010203Z-abcdef12"
paths := sessionPathsForEnv(env, m.SessionID)
mergedPath := filepath.Join(paths.TranscriptsDir, "base.json")
writeFile(t, mergedPath, `{"segments":[]}`)
setCurrentBuiltInEvidence(t, m, "merge", artifacts.TranscriptOutputKindBase, artifacts.ArtifactTranscriptBase, mergedPath)
writeFile(t, filepath.Join(paths.InputsDir, "glossary.yml"), "terms: []\n")
failure := errors.New("audita exited after output")
var runOutput string
env.Audita = polishRunnerFunc(func(_ context.Context, req audita.PolishRequest) (audita.PolishResult, error) {
runOutput = req.OutputProcessedPath
writeFile(t, runOutput, `{"segments":[]}`)
writeFile(t, filepath.Join(filepath.Dir(runOutput), "errors.yml"), "status: failed\n")
return audita.PolishResult{ProcessedTranscriptPath: runOutput}, failure
})
_, err := (polishStage{}).Run(context.Background(), env, m)
if !errors.Is(err, failure) || !strings.Contains(err.Error(), filepath.Dir(runOutput)) {
t.Fatalf("error = %v, want original failure with output directory", err)
}
if _, err := os.Stat(filepath.Join(paths.TranscriptsDir, "polished.json")); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("failed output was promoted: %v", err)
}
if _, err := os.Stat(filepath.Join(filepath.Dir(runOutput), "errors.yml")); err != nil {
t.Fatalf("run-local diagnostic missing: %v", err)
}
}
func TestPolishStageRejectsRedirectedReportPath(t *testing.T) {
env, m := setupPolishEnv(t)
env.Config.Session.Campaign = "sample-campaign"
m.Campaign = "sample-campaign"
m.RunID = "20260518T010203Z-abcdef12"
paths := sessionPathsForEnv(env, m.SessionID)
mergedPath := filepath.Join(paths.TranscriptsDir, "base.json")
writeFile(t, mergedPath, `{"segments":[]}`)
setCurrentBuiltInEvidence(t, m, "merge", artifacts.TranscriptOutputKindBase, artifacts.ArtifactTranscriptBase, mergedPath)
writeFile(t, filepath.Join(paths.InputsDir, "glossary.yml"), "terms: []\n")
redirected := filepath.Join(t.TempDir(), "errors.yml")
writeFile(t, redirected, "status: completed\n")
env.Audita = &audita.FakeRunner{Result: audita.PolishResult{Reports: audita.ReportBundle{ErrorsPath: redirected}}}
_, err := (polishStage{}).Run(context.Background(), env, m)
if err == nil || !strings.Contains(err.Error(), "did not match requested path") {
t.Fatalf("error = %v, want authoritative report path rejection", err)
}
if _, err := os.Stat(filepath.Join(paths.TranscriptsDir, "polished.json")); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("report-path failure promoted output: %v", err)
}
}
func TestPolishStageFailsWhenProcessedOutputInvalid(t *testing.T) { func TestPolishStageFailsWhenProcessedOutputInvalid(t *testing.T) {
env, m := setupPolishEnv(t) env, m := setupPolishEnv(t)
paths := sessionPathsForEnv(env, m.SessionID) paths := sessionPathsForEnv(env, m.SessionID)
@@ -185,25 +237,6 @@ func TestPolishStageFailsWhenProcessedOutputInvalid(t *testing.T) {
} }
} }
func TestPolishStageFailsWhenReportInvalid(t *testing.T) {
env, m := setupPolishEnv(t)
paths := sessionPathsForEnv(env, m.SessionID)
writeFile(t, filepath.Join(paths.TranscriptsDir, "base.json"), `{"segments":[]}`)
setCurrentBuiltInEvidence(t, m, "merge", artifacts.TranscriptOutputKindBase, artifacts.ArtifactTranscriptBase, filepath.Join(paths.TranscriptsDir, "base.json"))
writeFile(t, filepath.Join(paths.InputsDir, "glossary.yml"), "terms: []\n")
badReport := filepath.Join(paths.ArtifactsDir, "bad.report.json")
writeFile(t, badReport, "not-json")
env.Audita = &audita.FakeRunner{Result: audita.PolishResult{ReportPath: badReport}}
_, err := (polishStage{}).Run(context.Background(), env, m)
if err == nil {
t.Fatal("expected error, got nil")
}
if !strings.Contains(err.Error(), "report") {
t.Fatalf("error = %q", err.Error())
}
}
func TestPolishStageUsesRunLocalPathsAndMaterializesCanonical(t *testing.T) { func TestPolishStageUsesRunLocalPathsAndMaterializesCanonical(t *testing.T) {
env, m := setupPolishEnv(t) env, m := setupPolishEnv(t)
env.Config.Session.Campaign = "sample-campaign" env.Config.Session.Campaign = "sample-campaign"
@@ -244,32 +277,19 @@ func setupPolishEnv(t *testing.T) (*Env, *manifest.Manifest) {
writeFile(t, sessionPath, "session_id: 2026-05-03\n") writeFile(t, sessionPath, "session_id: 2026-05-03\n")
writeFile(t, pipelinePath, "workspace:\n root: "+workspace+"\n") writeFile(t, pipelinePath, "workspace:\n root: "+workspace+"\n")
report := true
totalLLMConcurrency := 3
proposalLLMConcurrency := 2
validationLLMConcurrency := 2
cfg := &config.Config{ cfg := &config.Config{
PipelinePath: pipelinePath, PipelinePath: pipelinePath,
SessionPath: sessionPath, SessionPath: sessionPath,
Pipeline: &config.PipelineConfig{ Pipeline: &config.PipelineConfig{
Workspace: config.WorkspaceConfig{Root: workspace}, Workspace: config.WorkspaceConfig{Root: workspace},
Audita: config.AuditaConfig{ Audita: config.AuditaConfig{
Binary: "audita", Binary: "audita",
Timeout: "3h", Timeout: "3h",
LLMAPIKey: testSecretReference("AUDITA_LLM_API_KEY"), Credentials: []configkit.Secret{*testSecretReference("AUDITA_LLM_API_KEY")},
Modules: []string{"glossary", "homophones", "grammar"}, Modules: []string{"glossary", "homophones", "grammar"},
BaseURL: "https://openrouter.ai/api/v1", TranscriptDescription: "Campaign Session 42",
Model: "openrouter/google/gemma-4-31b-it", ConfigPath: "/etc/audita/config.yml",
TranscriptDescription: "Campaign Session 42", OutputSchema: "audita-v1",
ConfigPath: "/etc/audita/config.yml",
OutputSchema: "audita-v1",
WorkDirRetention: "auto",
ValidationModel: "openrouter/google/gemma-4-31b-it",
TotalLLMConcurrency: &totalLLMConcurrency,
ProposalLLMConcurrency: &proposalLLMConcurrency,
ValidationLLMConcurrency: &validationLLMConcurrency,
Report: &report,
}, },
}, },
Session: &config.SessionConfig{ Session: &config.SessionConfig{

View File

@@ -1131,6 +1131,32 @@ func TestPublishFailsWithoutObjectStore(t *testing.T) {
} }
} }
func TestPublishArchivesCurrentPolishReportsOnlyAsDiagnostics(t *testing.T) {
env, m, runRoot := publishFixture(t)
polish := m.Stages["polish"]
polish.Outputs = nil
for _, name := range []string{"errors.yml", "recoveries.yml", "report.md"} {
path := filepath.Join(runRoot, "polish", "outputs", "transcripts", name)
writeStageTestFile(t, path, "diagnostic\n")
polish.Logs = append(polish.Logs, path)
}
if _, err := (publishStage{}).Run(context.Background(), env, m); err != nil {
t.Fatalf("publish reports: %v", err)
}
fake := env.ObjectStore.(*storage.FakeBackend)
for _, name := range []string{"errors.yml", "recoveries.yml", "report.md"} {
relative := "polish/outputs/transcripts/" + name
if _, ok := fake.Objects[m.S3RunPrefix+relative]; !ok {
t.Fatalf("missing run-archive diagnostic %q", relative)
}
for key := range fake.Objects {
if strings.Contains(key, "published/"+name) {
t.Fatalf("report was published as canonical output: %q", key)
}
}
}
}
func publishFixture(t *testing.T) (*Env, *manifest.Manifest, string) { func publishFixture(t *testing.T) (*Env, *manifest.Manifest, string) {
t.Helper() t.Helper()

View File

@@ -192,9 +192,10 @@ func TestExtractSemanticConfigExcludesLoadedCredentialChanges(t *testing.T) {
first := loadNotariusCredentialForSemanticTest(t, firstName, "first-value") first := loadNotariusCredentialForSemanticTest(t, firstName, "first-value")
rotated := loadNotariusCredentialForSemanticTest(t, firstName, "rotated-value") rotated := loadNotariusCredentialForSemanticTest(t, firstName, "rotated-value")
renamed := loadNotariusCredentialForSemanticTest(t, secondName, "second-value") renamed := loadNotariusCredentialForSemanticTest(t, secondName, "second-value")
third := loadNotariusCredentialForSemanticTest(t, "NARRATIO_SEMANTIC_NOTARIUS_KEY_THREE", "third-value")
baseline := downstreamSemanticEnv() baseline := downstreamSemanticEnv()
baseline.Config.Pipeline.Notarius.LLMAPIKey = first baseline.Config.Pipeline.Notarius.Credentials = []configkit.Secret{*first}
want, err := (extractStage{}).SemanticConfigFingerprint(baseline) want, err := (extractStage{}).SemanticConfigFingerprint(baseline)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@@ -209,7 +210,9 @@ func TestExtractSemanticConfigExcludesLoadedCredentialChanges(t *testing.T) {
} { } {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
env := downstreamSemanticEnv() env := downstreamSemanticEnv()
env.Config.Pipeline.Notarius.LLMAPIKey = test.credential if test.credential != nil {
env.Config.Pipeline.Notarius.Credentials = []configkit.Secret{*test.credential}
}
got, err := (extractStage{}).SemanticConfigFingerprint(env) got, err := (extractStage{}).SemanticConfigFingerprint(env)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@@ -219,20 +222,28 @@ func TestExtractSemanticConfigExcludesLoadedCredentialChanges(t *testing.T) {
} }
}) })
} }
baseline.Config.Pipeline.Notarius.Credentials = []configkit.Secret{*renamed, *third}
multiple, err := (extractStage{}).SemanticConfigFingerprint(baseline)
if err != nil {
t.Fatal(err)
}
if !want.Equal(multiple) {
t.Fatal("multiple credential references altered extract semantic fingerprint")
}
} }
func loadNotariusCredentialForSemanticTest(t *testing.T, name, value string) *configkit.Secret { func loadNotariusCredentialForSemanticTest(t *testing.T, name, value string) *configkit.Secret {
t.Helper() t.Helper()
t.Setenv(name, value) t.Setenv(name, value)
path := filepath.Join(t.TempDir(), "pipeline.yml") path := filepath.Join(t.TempDir(), "pipeline.yml")
if err := os.WriteFile(path, []byte("whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n llm_api_key: "+name+"\n"), 0o644); err != nil { if err := os.WriteFile(path, []byte("whisperx:\n transcribe_url: https://transcription.example.test/transcribe\nnotarius:\n enabled: false\n credentials: ["+name+"]\n"), 0o644); err != nil {
t.Fatal(err) t.Fatal(err)
} }
pipeline, err := config.LoadPipeline(path) pipeline, err := config.LoadPipeline(path)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
return pipeline.Notarius.LLMAPIKey return &pipeline.Notarius.Credentials[0]
} }
func TestPublishSemanticConfigSensitivityAndOperationalExclusions(t *testing.T) { func TestPublishSemanticConfigSensitivityAndOperationalExclusions(t *testing.T) {

View File

@@ -2,7 +2,6 @@ package stage
import ( import (
"fmt" "fmt"
"sort"
"strings" "strings"
"gitea.maximumdirect.net/eric/narratio/internal/artifacts" "gitea.maximumdirect.net/eric/narratio/internal/artifacts"
@@ -11,20 +10,20 @@ import (
) )
const ( const (
polishSemanticConfigVersion = 1 polishSemanticConfigVersion = 2
normalizeSemanticConfigVersion = 1 normalizeSemanticConfigVersion = 1
trimSemanticConfigVersion = 1 trimSemanticConfigVersion = 1
renderSemanticConfigVersion = 1 renderSemanticConfigVersion = 1
) )
type polishSemanticConfig struct { type polishSemanticConfig struct {
ServiceURL string `json:"service_url"`
Model string `json:"model"`
ValidationModel string `json:"validation_model"`
Modules []string `json:"modules"` Modules []string `json:"modules"`
Overlay string `json:"overlay"`
ProposalProfile string `json:"proposal_profile"`
ValidationProfile string `json:"validation_profile"`
TranscriptDescription string `json:"transcript_description"` TranscriptDescription string `json:"transcript_description"`
OutputSchema string `json:"output_schema"` OutputSchema string `json:"output_schema"`
ExternalConfig string `json:"external_config"` ConfigPath string `json:"config_path"`
OutputIdentity string `json:"output_identity"` OutputIdentity string `json:"output_identity"`
} }
@@ -68,19 +67,21 @@ func (polishStage) SemanticConfigFingerprint(env *Env) (manifest.SemanticConfigF
return manifest.SemanticConfigFingerprint{}, fmt.Errorf("polish semantic configuration requires resolved pipeline config") return manifest.SemanticConfigFingerprint{}, fmt.Errorf("polish semantic configuration requires resolved pipeline config")
} }
audita := env.Config.Pipeline.Audita audita := env.Config.Pipeline.Audita
modules := append([]string(nil), audita.Modules...) var modules []string
if audita.Modules != nil {
modules = append([]string{}, audita.Modules...)
}
for index := range modules { for index := range modules {
modules[index] = strings.TrimSpace(modules[index]) modules[index] = strings.TrimSpace(modules[index])
} }
sort.Strings(modules)
return FingerprintSemanticConfig(polishSemanticConfigVersion, polishSemanticConfig{ return FingerprintSemanticConfig(polishSemanticConfigVersion, polishSemanticConfig{
ServiceURL: strings.TrimSpace(audita.BaseURL),
Model: strings.TrimSpace(audita.Model),
ValidationModel: strings.TrimSpace(audita.ValidationModel),
Modules: modules, Modules: modules,
TranscriptDescription: strings.TrimSpace(audita.TranscriptDescription), Overlay: audita.Overlay,
OutputSchema: strings.TrimSpace(audita.OutputSchema), ProposalProfile: audita.ProposalProfile,
ExternalConfig: strings.TrimSpace(audita.ConfigPath), ValidationProfile: audita.ValidationProfile,
TranscriptDescription: audita.TranscriptDescription,
OutputSchema: audita.OutputSchema,
ConfigPath: audita.ConfigPath,
OutputIdentity: artifacts.ArtifactTranscriptPolished, OutputIdentity: artifacts.ArtifactTranscriptPolished,
}) })
} }

View File

@@ -3,6 +3,7 @@ package stage
import ( import (
"testing" "testing"
configkit "gitea.maximumdirect.net/eric/ConfigKit"
"gitea.maximumdirect.net/eric/narratio/internal/config" "gitea.maximumdirect.net/eric/narratio/internal/config"
) )
@@ -11,33 +12,48 @@ func TestPolishSemanticConfigSensitivity(t *testing.T) {
name string name string
mutate func(*Env) mutate func(*Env)
}{ }{
{name: "model", mutate: func(env *Env) { env.Config.Pipeline.Audita.Model = "production" }},
{name: "validation model", mutate: func(env *Env) { env.Config.Pipeline.Audita.ValidationModel = "validator-v2" }},
{name: "modules", mutate: func(env *Env) { env.Config.Pipeline.Audita.Modules = []string{"terms", "speakers", "style"} }}, {name: "modules", mutate: func(env *Env) { env.Config.Pipeline.Audita.Modules = []string{"terms", "speakers", "style"} }},
{name: "module order", mutate: func(env *Env) { env.Config.Pipeline.Audita.Modules = []string{"terms", "speakers"} }},
{name: "module repetition", mutate: func(env *Env) { env.Config.Pipeline.Audita.Modules = []string{"speakers", "terms", "terms"} }},
{name: "modules omitted", mutate: func(env *Env) { env.Config.Pipeline.Audita.Modules = nil }},
{name: "modules empty", mutate: func(env *Env) { env.Config.Pipeline.Audita.Modules = []string{} }},
{name: "overlay", mutate: func(env *Env) { env.Config.Pipeline.Audita.Overlay = "testing" }},
{name: "proposal profile", mutate: func(env *Env) { env.Config.Pipeline.Audita.ProposalProfile = "draft" }},
{name: "validation profile", mutate: func(env *Env) { env.Config.Pipeline.Audita.ValidationProfile = "review" }},
{name: "description", mutate: func(env *Env) { env.Config.Pipeline.Audita.TranscriptDescription = "live campaign" }}, {name: "description", mutate: func(env *Env) { env.Config.Pipeline.Audita.TranscriptDescription = "live campaign" }},
{name: "schema", mutate: func(env *Env) { env.Config.Pipeline.Audita.OutputSchema = "audita.transcript.v2" }}, {name: "schema", mutate: func(env *Env) { env.Config.Pipeline.Audita.OutputSchema = "audita.transcript.v2" }},
{name: "external config", mutate: func(env *Env) { env.Config.Pipeline.Audita.ConfigPath = "configs/other.yml" }}, {name: "external config", mutate: func(env *Env) { env.Config.Pipeline.Audita.ConfigPath = "configs/other.yml" }},
{name: "service", mutate: func(env *Env) { env.Config.Pipeline.Audita.BaseURL = "https://other.example" }},
} }
assertRefinementChanges(t, polishStage{}, semantic) assertRefinementChanges(t, polishStage{}, semantic)
assertRefinementUnchanged(t, polishStage{}, []struct { assertRefinementUnchanged(t, polishStage{}, []struct {
name string name string
mutate func(*Env) mutate func(*Env)
}{ }{
{name: "module order", mutate: func(env *Env) { env.Config.Pipeline.Audita.Modules = []string{"terms", "speakers"} }},
{name: "runner settings", mutate: func(env *Env) { {name: "runner settings", mutate: func(env *Env) {
env.Config.Pipeline.Audita.Binary = "/opt/audita" env.Config.Pipeline.Audita.Binary = "/opt/audita"
env.Config.Pipeline.Audita.Timeout = "1h" env.Config.Pipeline.Audita.Timeout = "1h"
env.Config.Pipeline.Audita.TotalLLMConcurrency = intPointer(20) env.Config.Pipeline.Audita.Credentials = []configkit.Secret{*testSecretReference("OTHER_KEY")}
env.Config.Pipeline.Audita.ProposalLLMConcurrency = intPointer(10)
env.Config.Pipeline.Audita.ValidationLLMConcurrency = intPointer(10)
env.Config.Pipeline.Audita.LLMAPIKey = testSecretReference("OTHER_KEY")
env.Config.Pipeline.Audita.WorkDirRetention = "always"
env.Config.Pipeline.Audita.Report = boolPointer(false)
}}, }},
}) })
} }
func TestPolishSemanticConfigDistinguishesOmittedAndExplicitlyEmptyModules(t *testing.T) {
env := refinementSemanticEnv()
env.Config.Pipeline.Audita.Modules = nil
omitted, err := (polishStage{}).SemanticConfigFingerprint(env)
if err != nil {
t.Fatal(err)
}
env.Config.Pipeline.Audita.Modules = []string{}
empty, err := (polishStage{}).SemanticConfigFingerprint(env)
if err != nil {
t.Fatal(err)
}
if omitted.Equal(empty) {
t.Fatal("omitted and explicitly empty module selections have equal semantic evidence")
}
}
func TestNormalizeSemanticConfigSensitivity(t *testing.T) { func TestNormalizeSemanticConfigSensitivity(t *testing.T) {
assertRefinementChanges(t, normalizeStage{}, []struct { assertRefinementChanges(t, normalizeStage{}, []struct {
name string name string
@@ -119,12 +135,9 @@ func refinementSemanticEnv() *Env {
env := initialSemanticEnv() env := initialSemanticEnv()
env.Config.Session.Title = "Session title" env.Config.Session.Title = "Session title"
env.Config.Pipeline.Audita = config.AuditaConfig{ env.Config.Pipeline.Audita = config.AuditaConfig{
Binary: "audita", Timeout: "10m", LLMAPIKey: testSecretReference("AUDITA_KEY"), Binary: "audita", Timeout: "10m", Credentials: []configkit.Secret{*testSecretReference("AUDITA_KEY")},
Modules: []string{"speakers", "terms"}, BaseURL: "https://audita.example", Modules: []string{"speakers", "terms"}, TranscriptDescription: "tabletop session",
Model: "testing", ValidationModel: "validator", TranscriptDescription: "tabletop session",
ConfigPath: "configs/audita.yml", OutputSchema: "audita.transcript.v1", ConfigPath: "configs/audita.yml", OutputSchema: "audita.transcript.v1",
TotalLLMConcurrency: intPointer(4), ProposalLLMConcurrency: intPointer(2),
ValidationLLMConcurrency: intPointer(2), WorkDirRetention: "failure", Report: boolPointer(true),
} }
env.Config.Pipeline.Normalize = &config.NormalizeConfig{ env.Config.Pipeline.Normalize = &config.NormalizeConfig{
OutputPath: "transcripts/final.json", OutputSchema: "seriatim.transcript.v1", Report: boolPointer(true), OutputPath: "transcripts/final.json", OutputSchema: "seriatim.transcript.v1", Report: boolPointer(true),

View File

@@ -156,39 +156,30 @@ func (state *transcribeExecutionState) checkpointCollectionLocked(
return fmt.Errorf("validate transcribe speaker collection: %w", err) return fmt.Errorf("validate transcribe speaker collection: %w", err)
} }
candidate := cloneManifestForTranscribeCheckpoint(state.manifest) missingRecord := transcribeStageRecord(state.manifest) == nil
if candidate.Stages == nil { if err := checkpointStageCollection(
candidate.Stages = make(map[string]*manifest.StageRecord) ctx,
} state.env.ManifestStore,
record := candidate.Stages["transcribe"] state.paths.ManifestPath,
if record == nil { state.manifest,
now := time.Now().UTC() "transcribe",
record = &manifest.StageRecord{ func(record *manifest.StageRecord) error {
Name: "transcribe", Status: manifest.StatusRunning, CreatedAt: now, UpdatedAt: now, if missingRecord {
} now := time.Now().UTC()
candidate.Stages["transcribe"] = record *record = manifest.StageRecord{
} Name: "transcribe", Status: manifest.StatusRunning, CreatedAt: now, UpdatedAt: now,
record.TranscribeStateVersion = manifest.TranscribeStateContractVersion }
record.TranscribeSpeakers = manifest.CloneTranscribeSpeakerCollection(records) }
record.UpdatedAt = time.Now().UTC() record.TranscribeStateVersion = manifest.TranscribeStateContractVersion
if err := state.env.ManifestStore.Save(ctx, state.paths.ManifestPath, candidate); err != nil { record.TranscribeSpeakers = manifest.CloneTranscribeSpeakerCollection(records)
return fmt.Errorf("save session manifest %q: %w", state.paths.ManifestPath, err) record.UpdatedAt = time.Now().UTC()
return nil
},
); err != nil {
return err
} }
live := transcribeStageRecord(state.manifest) live := transcribeStageRecord(state.manifest)
if live == nil {
live = &manifest.StageRecord{}
if state.manifest.Stages == nil {
state.manifest.Stages = make(map[string]*manifest.StageRecord)
}
state.manifest.Stages["transcribe"] = live
}
live.TranscribeStateVersion = candidate.Stages["transcribe"].TranscribeStateVersion
live.TranscribeSpeakers = manifest.CloneTranscribeSpeakerCollection(
candidate.Stages["transcribe"].TranscribeSpeakers,
)
live.UpdatedAt = candidate.Stages["transcribe"].UpdatedAt
state.manifest.UpdatedAt = candidate.UpdatedAt
state.records = manifest.CloneTranscribeSpeakerCollection(live.TranscribeSpeakers) state.records = manifest.CloneTranscribeSpeakerCollection(live.TranscribeSpeakers)
return nil return nil
} }
@@ -259,27 +250,6 @@ func transcribeStageRecord(m *manifest.Manifest) *manifest.StageRecord {
return m.Stages["transcribe"] return m.Stages["transcribe"]
} }
func cloneManifestForTranscribeCheckpoint(source *manifest.Manifest) *manifest.Manifest {
clone := *source
clone.Inputs = append([]manifest.InputRecord(nil), source.Inputs...)
clone.Artifacts = append([]manifest.ArtifactRecord(nil), source.Artifacts...)
clone.Stages = make(map[string]*manifest.StageRecord, len(source.Stages))
for name, sourceRecord := range source.Stages {
if sourceRecord == nil {
clone.Stages[name] = nil
continue
}
record := *sourceRecord
record.Outputs = append([]manifest.ArtifactRecord(nil), sourceRecord.Outputs...)
record.Logs = append([]string(nil), sourceRecord.Logs...)
record.GeneratedConfigs = append([]string(nil), sourceRecord.GeneratedConfigs...)
record.TranscribeSpeakers = manifest.CloneTranscribeSpeakerCollection(sourceRecord.TranscribeSpeakers)
record.AnalyzeArtifacts = manifest.CloneAnalyzeArtifactCollection(sourceRecord.AnalyzeArtifacts)
clone.Stages[name] = &record
}
return &clone
}
func cloneStringAnyMap(source map[string]any) map[string]any { func cloneStringAnyMap(source map[string]any) map[string]any {
if source == nil { if source == nil {
return nil return nil

View File

@@ -58,7 +58,7 @@ func TestTranscribeResumeAcceptsEquivalentOutputsAndInspectsRemovalReadOnly(t *t
t.Fatalf("equivalent aggregate: %#v, %v", validation, err) t.Fatalf("equivalent aggregate: %#v, %v", validation, err)
} }
m.Inputs = slices.DeleteFunc(m.Inputs, func(in manifest.InputRecord) bool { return filepath.Base(in.Path) == "bob.flac" }) m.Inputs = slices.DeleteFunc(m.Inputs, func(in manifest.InputRecord) bool { return filepath.Base(in.Path) == "bob.flac" })
before := cloneManifestForTranscribeCheckpoint(m) before := cloneManifestForCheckpoint(m)
validation, err = (transcribeStage{}).ValidateResume(context.Background(), env, m) validation, err = (transcribeStage{}).ValidateResume(context.Background(), env, m)
if err != nil || validation.Resumable { if err != nil || validation.Resumable {
t.Fatalf("removed speaker: %#v, %v", validation, err) t.Fatalf("removed speaker: %#v, %v", validation, err)