@am_shork/attest 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -316,21 +316,13 @@ export async function runVerify(root, options = {}) {
316
316
  specFiles: scan.specFiles.length,
317
317
  attesting: attesting.length,
318
318
  };
319
- // A run with nothing to attest used to print "✓ No issues." and exit 0,
320
- // because "no failing tests" was read as passed. An empty registry is the
321
- // only shape of that which no other check already catches: with at least one
322
- // requirement, an absent scenario is `uncovered-requirement` and a declared
323
- // scenario that never executed is `declared-not-run`, both ERRORs. So this is
324
- // narrower than "zero scenarios ran" and firing on that too would only
325
- // double-report a run that is already red.
326
- if (counts.requirements === 0) {
327
- issues.push({
328
- level: 'ERROR',
329
- code: 'empty-spec',
330
- message: `No requirements found under this root, so this run attested nothing. ` +
331
- `Point attest at the directory holding your *.reqs.ts files, or add one.`,
332
- });
333
- }
319
+ // `empty-spec` belongs to `validateStructure` above, not here: the registry
320
+ // alone decides it, so it is owed by every command performing §5.3 rather than
321
+ // by the one that executes. The guard a reader is most likely to want here is
322
+ // "zero scenarios ran", and it is deliberately not that — with at least one
323
+ // requirement, an absent scenario is already `uncovered-requirement` and a
324
+ // declared scenario that never executed is already `declared-not-run`, both
325
+ // ERRORs, so the wider rule would only double-report a run that is red anyway.
334
326
  // Nothing declares intent, so there is nothing for Attest to run. Skipping
335
327
  // the child run keeps an incumbent suite untouched; the verdict comes from
336
328
  // empty-spec or uncovered-requirement, both already ERRORs above.
@@ -813,14 +805,44 @@ export async function runStatus(root, changeName, options = {}) {
813
805
  return nothing([invalidChangeNameIssue(changeName)]);
814
806
  if (unusable)
815
807
  return nothing([unusable]);
816
- const read = await readDelta(root, changeName, options);
817
- if ('issue' in read)
818
- return nothing([read.issue]);
819
- const scan = await scanProject(root);
820
- const { merged: plan } = await changeMergedPlan(root, read.delta, scan);
821
- const firstRun = await readRedRecord(root, changeName);
822
- const rows = statusRows(addedIds(read.delta), plan, firstRun);
823
- return { change: changeName, rows, counts: statusCounts(rows), issues: [] };
808
+ // One loader for the whole command, or none at all. Both reads below take the
809
+ // reader `options` asks for, so the escape hatch moves them together: the
810
+ // default path evaluates nothing, which is what puts this command on ATX-16's
811
+ // roster, and `--eval` is one named decision rather than one per file.
812
+ return withLoader(options, async (loader) => {
813
+ const read = await readDelta(root, changeName, options, loader);
814
+ if ('issue' in read)
815
+ return nothing([read.issue]);
816
+ const scan = await scanProject(root);
817
+ const { registry: base, issues: registryIssues } = await readRegistry(root, options, scan.reqsFiles, loader);
818
+ // `hasError`, the gate's own predicate over the same list, because the
819
+ // registry is what the delta is applied *to*: without it there is no end
820
+ // state to describe, and a report computed against half a registry would
821
+ // answer about a change nobody proposed.
822
+ if (hasError(registryIssues))
823
+ return nothing(registryIssues);
824
+ // The gate's own call, made here for its diagnosis rather than its result:
825
+ // the rows below stay decided by the delta, the specs and the record alone
826
+ // (ATX-32), and what this adds is the refusal. A delta that cannot be
827
+ // applied describes an end state that does not exist, so there is no
828
+ // progress toward it to report — an `unproven` against it would be a
829
+ // true-looking sentence about a change that cannot exist.
830
+ const { issues: deltaIssues } = applyDelta(base, read.delta);
831
+ if (deltaIssues.length > 0)
832
+ return nothing(deltaIssues);
833
+ const { merged: plan, issues: unreadableSpecs } = await changeMergedPlan(root, read.delta, scan);
834
+ // The same refusal the gate makes, from the same list and on the same
835
+ // argument (ATX-65): every state this command reports is computed *from* the
836
+ // plan, so a spec the parser could not read does not shrink the report — it
837
+ // changes what the remaining rows say. A requirement whose only scenario is
838
+ // in that file reads as having none, which is the opposite of the truth and
839
+ // is advice to redo work already on disk.
840
+ if (unreadableSpecs.length > 0)
841
+ return nothing(unreadableSpecs);
842
+ const firstRun = await readRedRecord(root, changeName);
843
+ const rows = statusRows(addedIds(read.delta), plan, firstRun);
844
+ return { change: changeName, rows, counts: statusCounts(rows), issues: [] };
845
+ });
824
846
  }
825
847
  /** Archive gate for a change (design §8, §9: `attest archive <change>`). */
826
848
  export async function runArchive(root, changeName, options = {}) {
@@ -34,9 +34,13 @@
34
34
  // workflow to an agent that trusts it. The backstop is that every mistake it
35
35
  // could cause is a diagnostic with a fix hint — a registry written the old way
36
36
  // is `registry-not-static`, and the agent corrects itself from the report.
37
- // It has happened once, so: read this file when a release adds a diagnostic.
38
- // Nothing gates that `ATX-57` catches a code the engine cannot emit, never one
39
- // it can.
37
+ // It has happened twice, the second time on a diagnostic that was not added but
38
+ // *redefined*the code table and the prose below it disagreed, and an agent
39
+ // branches on the table. So: read this file when a release adds a diagnostic
40
+ // **or changes what one means**, and grep this string for the code rather than
41
+ // trusting that the section you edited was its only mention. Nothing gates it —
42
+ // `ATX-57` catches a code the engine cannot emit, never one it can, and its
43
+ // rationale records that one-directionality as deliberate.
40
44
  /**
41
45
  * The one sentence that decides whether the workflow is ever loaded.
42
46
  *
@@ -128,11 +132,16 @@ promises is a two-stage workflow, and the stages are separate on purpose.
128
132
  or it is an \`unbound-param\` ERROR. A \`{placeholder}\` written into a
129
133
  *rationale* is a \`rationale-placeholder\` WARNING — rationales are not
130
134
  interpolated, so it would reach the rendered document with its braces intact.
131
- - **A registry is a literal.** Every value is written in the file: no imported
132
- constant (\`params: { maxMb: MAX_MB }\`), no computed value, no \`Date.now()\`.
133
- \`check\`, \`cover\` and \`render\` read \`*.reqs.ts\` with the compiler API and
134
- never execute it, so anything they cannot read is a \`registry-not-static\`
135
- ERROR. An imported constant also breaks the single-source rule outright — the
135
+ - **A registry is a literal, and so is a delta.** Every value is written in the
136
+ file: no imported constant (\`params: { maxMb: MAX_MB }\`), no computed value,
137
+ no \`Date.now()\`. \`check\`, \`cover\` and \`render\` read \`*.reqs.ts\` with the
138
+ compiler API and never execute it, so anything they cannot read is a
139
+ \`registry-not-static\` ERROR. **The same rule covers
140
+ \`requirements.delta.ts\`**, which \`check\` and \`status\` read the same way — a
141
+ \`const\` lifted out of a delta is that same error, and a delta is the more
142
+ exposed of the two, living in \`changes/\` — the part of the tree that is by
143
+ definition still under review.
144
+ An imported constant also breaks the single-source rule outright — the
136
145
  value's real owner is then somewhere else. Inline it, and have the application
137
146
  code read it from the registry.
138
147
  - **Write prose as one long single-line string.** A template literal with no
@@ -176,13 +185,31 @@ lib/game/specs/
176
185
  └── fog.proposed.spec.ts # this change's, and ../fog already resolves
177
186
  \`\`\`
178
187
 
179
- That name is the whole mechanism. It keeps the file out of \`attest verify\` and
180
- out of a plain \`vitest run\` while the change is in flight — the scenarios are
181
- red by construction — and \`attest archive <name>\` pulls it in by the requirement
182
- ids it covers: a change claims the proposed specs that declare a scenario for an
183
- id it ADDs, renames to, or MODIFIEs. Nothing lists paths anywhere, so nothing can
184
- fall out of step. A proposed spec no change claims is a \`proposed-spec-unclaimed\`
185
- ERROR from \`attest check\`, because it would otherwise run nowhere at all.
188
+ That name is the whole mechanism. It keeps the file out of \`attest verify\`
189
+ while the change is in flight — the scenarios are red by construction — and
190
+ \`attest archive <name>\` pulls it in by the requirement ids it covers: a change
191
+ claims the proposed specs that declare a scenario for an id it ADDs, renames to,
192
+ or MODIFIEs. Nothing lists paths anywhere, so nothing can fall out of step. A
193
+ proposed spec no change claims is a \`proposed-spec-unclaimed\` ERROR from
194
+ \`attest check\`, because it would otherwise run nowhere at all.
195
+
196
+ **It does not hide the file from your own test command.** \`*.proposed.spec.ts\`
197
+ still ends in \`.spec.ts\`, so an ordinary \`**/*.spec.ts\` include — Vitest's own
198
+ default among them — picks it up, and during stage 1 those scenarios are
199
+ *supposed* to fail. Only Attest's scope excludes them. If a red \`npm test\` while
200
+ a change is in flight is a problem for you, exclude the pattern in your own
201
+ config; that is a decision about your suite, and Attest does not make it for you:
202
+
203
+ \`\`\`ts
204
+ // vitest.config.ts — optional, and only if you want your own suite green
205
+ import { configDefaults, defineConfig } from 'vitest/config';
206
+
207
+ export default defineConfig({
208
+ // Spread the defaults: a bare \`exclude\` REPLACES them, and Vitest's include
209
+ // reaches node_modules without them.
210
+ test: { exclude: [...configDefaults.exclude, '**/*.proposed.spec.ts'] },
211
+ });
212
+ \`\`\`
186
213
 
187
214
  Writing it at its merged location is what makes merging it a rename. Its relative
188
215
  imports resolve now exactly as they will afterwards, so \`../fog\` never becomes
@@ -279,11 +306,17 @@ To see where the change stands at any point, without paying for a run:
279
306
  attest status <name> --json # per added requirement: no-scenario / unproven / proven
280
307
  \`\`\`
281
308
 
282
- It reads the delta, the specs and \`first-run.json\`, and reports what the gate
283
- will still want. A change in flight is \`ok: true\` with rows to work through —
284
- this command never fails on unmet obligations, so do not read a clean table as
285
- "done". The state it cannot see is whether the tests pass; \`attest archive\` is
286
- the only thing that answers that.
309
+ It reads the delta, the specs and \`first-run.json\`, and reports **two** of the
310
+ gate's obligations, for the ids this change ADDs only: does each have a scenario,
311
+ and has each scenario been recorded failing. A change in flight is \`ok: true\`
312
+ with rows to work through this command never fails on unmet obligations, so do
313
+ not read a clean table as "done".
314
+
315
+ **Everything else the gate checks is invisible here**, and that is more than
316
+ whether the tests pass. A scenario left \`skip\`ped is \`declared-not-run\` and
317
+ blocks the gate with the suite fully green; so does a spec file that will not
318
+ import, or a proposed spec no delta claims. A clean table plus green tests is
319
+ still not a verdict — \`attest archive\` is the only thing that decides.
287
320
 
288
321
  Then present the proposal, the ids, and the red output, and **stop**. Wait for
289
322
  agreement before implementing.
@@ -317,9 +350,32 @@ once. Branch on \`issues[].code\`, never on \`message\`:
317
350
  | \`add-conflict\` | the delta adds an id that already exists with different content |
318
351
  | \`change-not-found\` | no \`requirements.delta.ts\` for that name |
319
352
  | \`proposed-spec-name-taken\` | a proposed spec's merged name is already held by another spec |
320
- | \`apply-unsupported-delta\` | \`--apply\` writes back ADDED only, and this delta carries more |
353
+ | \`apply-unsupported-delta\` | \`--apply\` writes back ADDED and MODIFIED; this delta carries RENAMED or REMOVED, or a MODIFIED value whose source span holds a comment |
321
354
  | \`apply-no-prefix-owner\` | no registry file owns the prefix of an id this change adds |
322
355
 
356
+ ### Iterating: run the spec directly, decide with the gate
357
+
358
+ The gate does everything above after every edit, which makes it the slowest
359
+ possible inner loop. While you are still making a scenario pass, run that one
360
+ file instead, and keep \`attest archive\` for when you think you are finished:
361
+
362
+ \`\`\`
363
+ vitest run path/to/fog.proposed.spec.ts
364
+ \`\`\`
365
+
366
+ Two things make that safe, and one keeps it from being a verdict:
367
+
368
+ - **It writes nothing.** \`first-run.json\` is only ever written by the gate, so
369
+ no number of direct runs can touch the record or the never-red obligation.
370
+ - **\`attest status <name>\` still answers the readable half** without a run,
371
+ exactly as in stage 1.
372
+ - **A green file here does not predict the gate.** Your config supplies aliases,
373
+ transforms and a DOM; the gate's child run is isolated (\`config: false\`) and
374
+ supplies none of them unless told to. So a scenario can pass directly and fail
375
+ under the gate — that gap is the first thing to suspect when it does. See
376
+ \`tests-red\` in the troubleshooting document, and \`--vitest-config\` if your
377
+ specs need that environment.
378
+
323
379
  ### Four things you must not do
324
380
 
325
381
  Each turns the gate green without changing the system, which is the exact
@@ -365,7 +421,8 @@ attest archive <name> --apply
365
421
  \`\`\`
366
422
 
367
423
  That finishes the merge the verdict just approved: it splices the change's ADDED
368
- requirements into the registry file owning their id prefix, repoints each proposed
424
+ requirements into the registry file owning their id prefix, writes each MODIFIED
425
+ requirement's changed values over the values they replace, repoints each proposed
369
426
  spec's import of \`requirements.delta.ts\` at that registry, renames the specs in
370
427
  place, and moves \`changes/<name>/\` to \`archive/<date>-<name>/\`. It re-runs the
371
428
  gate first and writes nothing if that fails, and it prints every path it touched.
@@ -379,10 +436,14 @@ Two things it does not do, and both are still yours:
379
436
  registry is a \`stale-spec-doc\` ERROR.
380
437
  2. **Run the merged suite.** \`attest verify\`, on the result, reported.
381
438
 
382
- **It writes back ADDED only.** A delta also carrying RENAMED, REMOVED or MODIFIED
383
- is refused whole as \`apply-unsupported-delta\`, with nothing written — the gate
384
- still checked all four, so nothing about the change is unverified, but the rest is
385
- merged by hand.
439
+ **It writes back ADDED and MODIFIED.** A delta also carrying RENAMED or REMOVED is
440
+ refused whole as \`apply-unsupported-delta\`, with nothing written — the gate still
441
+ checked all four, so nothing about the change is unverified, but the rest is merged
442
+ by hand. The same code refuses one MODIFIED *value* when a comment sits inside the
443
+ span it would write over: the edit replaces a value and never the entry holding it,
444
+ so \`statement\` and \`rationale\` can never hit this, while a \`params\` value or an
445
+ \`outOfScope\` list can. Move the comment beside the value it belongs to, and run
446
+ the command again.
386
447
 
387
448
  Merging by hand, when it refuses: splice the delta's entries into the registry
388
449
  file that owns their prefix; then for each \`*.proposed.spec.ts\`, **repoint its
@@ -400,7 +461,7 @@ move, so nothing else about it does either. Then move the change folder.
400
461
  | \`attest cover\` | which requirements lack a scenario. |
401
462
  | \`attest render\` | the registry as Markdown for human readers; \`--check\` gates a committed copy. |
402
463
  | \`attest archive <change>\` | the completion gate for a proposed change; \`--apply\` also performs the merge it approves. |
403
- | \`attest status <change>\` | what that gate still wants, without running the suite. |
464
+ | \`attest status <change>\` | per id the change ADDs, two of the gate's obligations — scenario written, seen red — read without running the suite. A strict subset of the gate, never a second one. |
404
465
 
405
466
  \`verify\` starts the child run **isolated** — it does not read \`vitest.config.ts\`,
406
467
  so a verdict never depends on ambient configuration. Specs needing transforms, a
@@ -36,6 +36,64 @@ export declare function requirementSource(id: string, req: Requirement, indent:
36
36
  * the same delta must produce the same file twice.
37
37
  */
38
38
  export declare function spliceRequirements(file: string, source: string, additions: Registry): string | undefined;
39
+ /**
40
+ * One requirement a change modifies: what the registry holds, and what the gate
41
+ * proved the end state to be.
42
+ *
43
+ * Both halves, rather than the delta's patch, for the reason `MergeInputs.applied`
44
+ * exists — the patch is the authoring shape and the end state is what was proved
45
+ * green. Which fields actually move is then a *derived* fact, computed here by
46
+ * comparing the two, so a delta that restates a value it does not change writes
47
+ * nothing.
48
+ */
49
+ export interface Modification {
50
+ id: string;
51
+ /** The entry as the file holds it — the gate's `base`. */
52
+ before: Requirement;
53
+ /** The entry as the gate proved it — `applied`. */
54
+ after: Requirement;
55
+ }
56
+ /**
57
+ * Why one value could not be written over, if it could not.
58
+ *
59
+ * `field` is `statement`, `outOfScope`, `params.totpWindowSec` — the path of the
60
+ * value, spelled the way the author would say it — and absent only when the
61
+ * refusal is about the entry rather than a value in it. The caller turns these
62
+ * into diagnostics; nothing here writes prose, because a refusal from this
63
+ * module refuses a whole merge and only the caller knows what to say about that.
64
+ */
65
+ export interface ModifyRefusal {
66
+ reqId: string;
67
+ field?: string;
68
+ reason: 'comment' | 'entry-not-found' | 'not-a-literal' | 'param-dropped';
69
+ }
70
+ export type ModifyResult = {
71
+ ok: true;
72
+ source: string;
73
+ } | {
74
+ ok: false;
75
+ refusals: ModifyRefusal[];
76
+ };
77
+ /**
78
+ * `source` with each modified requirement's **changed values** written over.
79
+ *
80
+ * The other half of `--apply`'s write-back, and the one the design refused for
81
+ * five releases. What makes it allowable is stated at the top of this file and
82
+ * is a property of *granularity*: this never replaces an entry, only the span of
83
+ * a value inside one. A `statement` is a single string literal, so a comment
84
+ * cannot be inside what it overwrites; a `params` key or an `outOfScope` list
85
+ * can be, and that span is the only place this has to ask. Everything else in
86
+ * the file — the keys, the commas, the layout, every comment attached to a field
87
+ * that did not move — is bytes this does not address.
88
+ *
89
+ * A refusal is per value and the caller's response is whole-merge: the list is
90
+ * returned complete rather than at the first one, so an author fixing them by
91
+ * hand sees the whole of what stopped it.
92
+ *
93
+ * `undefined` under the same condition `spliceRequirements` returns it, through
94
+ * the same reader.
95
+ */
96
+ export declare function spliceModifications(file: string, source: string, changes: readonly Modification[]): ModifyResult | undefined;
39
97
  /**
40
98
  * `source` with every import of `from` repointed at `to`.
41
99
  *
@@ -45,9 +103,10 @@ export declare function spliceRequirements(file: string, source: string, additio
45
103
  * discipline as the splice, for the same reason.
46
104
  *
47
105
  * The extension is taken from the specifier being replaced rather than chosen
48
- * here. Whether a project writes `./x.reqs.js` or `./x.reqs.ts` is a property of
49
- * its module resolution, uniform across the project, and already answered by the
50
- * specifier sitting in front of us.
106
+ * here. Whether a project writes `./x.reqs.js`, `./x.reqs.ts` or `./x.reqs` is a
107
+ * property of its module resolution, uniform across the project, and already
108
+ * answered by the specifier sitting in front of us — the third spelling
109
+ * included, where the answer is "none".
51
110
  */
52
111
  export declare function repointImport(file: string, source: string, from: string, to: string): string;
53
112
  //# sourceMappingURL=splice.d.ts.map