packstruct 1.0.0 → 1.1.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.
- package/README.md +41 -53
- package/bin/cli.mjs +97 -22
- package/conformance/cases/env-claims/public/env-claims-pack/entry.js +4 -0
- package/conformance/cases/env-claims/public/env-claims-pack/pack.json +16 -0
- package/package.json +23 -5
- package/profiles/check.md +7 -27
- package/profiles/scenario.md +9 -24
- package/spec/SPEC.md +82 -118
- package/src/audit.mjs +75 -2
- package/src/lint.mjs +247 -97
- package/src/new.mjs +79 -0
- package/src/run-capped.mjs +16 -10
package/spec/SPEC.md
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
# The packstruct spec, version 1
|
|
2
2
|
|
|
3
|
-
One `/packs` system, many hosts. This document is normative for any app that
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
production pack ships schemaVersion 1 with exactly the shared field set (8/8
|
|
8
|
-
conform, nothing drifted since the 2026-10-23 audit). The id space is clean:
|
|
9
|
-
44 pack ids across the 8 packs, zero collisions pack-vs-pack and
|
|
10
|
-
pack-vs-library. v1 formalizes that reality; hosts either already conform
|
|
11
|
-
(crashtest) or adopt it fresh (poststruct). Baseline watch: if a host fleet
|
|
12
|
-
bumps its manifests, the spec formalizes the new number - the spec tags
|
|
13
|
-
whatever the fleet ships. Ordering ruled on crashtest#19: code first, spec
|
|
14
|
-
formalizes after; nothing schema-changing is hidden on the engine side.
|
|
3
|
+
One `/packs` system, many hosts. This document is normative for any app that loads packs from a `packs/` directory and for anyone authoring a pack.
|
|
4
|
+
|
|
5
|
+
**Revision history.** v1.0.0 froze the manifest table against crashtest's production reality. v1.1.0 is the additive-first patch section 6 promises: five rows, every one citing an ENGINE receipt (behavior at least one host loader already holds), none moving `schemaVersion` and none changing a conforming host's behavior. See section 8 for the adopted rows.
|
|
6
|
+
|
|
7
|
+
**Schema base (verified 2026-10-24, crashtest#19 receipts):** every crashtest production pack ships schemaVersion 1 with exactly the shared field set (8/8 conform, nothing drifted since the 2026-10-23 audit). The id space is clean: 44 pack ids across the 8 packs, zero collisions pack-vs-pack and pack-vs-library. v1 formalizes that reality; hosts either already conform (crashtest) or adopt it fresh (poststruct). Baseline watch: if a host fleet bumps its manifests, the spec formalizes the new number - the spec tags whatever the fleet ships. Ordering ruled on crashtest#19: code first, spec formalizes after; nothing schema-changing is hidden on the engine side.
|
|
15
8
|
|
|
16
9
|
## 1. Directory contract (all hosts)
|
|
17
10
|
|
|
@@ -21,6 +14,8 @@ packs/public/<pack-name>/
|
|
|
21
14
|
<entry file> # REQUIRED: the file pack.json's "entry" names
|
|
22
15
|
```
|
|
23
16
|
|
|
17
|
+
**The contract root.** The lint/audit contract root is the packs ROOT - `<dir>/` with its `public/` (tracked) and `local/` (gitignored WIP) children - never `packs/public/` itself. This spec page is the canonical statement of that rule; a host that mirrors it in its own CLI reference cites this section rather than restating it (crashtest's `lint-packs` page is the first mirror, `docs/reference/cli.md`).
|
|
18
|
+
|
|
24
19
|
## 2. pack.json (frozen for v1)
|
|
25
20
|
|
|
26
21
|
| Field | Rules |
|
|
@@ -29,136 +24,105 @@ packs/public/<pack-name>/
|
|
|
29
24
|
| `name` | kebab-case string, MUST match its directory name (mismatch = load refuse) |
|
|
30
25
|
| `description` | one-line, human-readable |
|
|
31
26
|
| `version` | dotted MAJOR.MINOR[.PATCH] |
|
|
32
|
-
| `entry` | relative path inside the pack dir, MUST exist (missing entry = instant, nameable refusal - the crashtest#16 lesson is a norm now) |
|
|
27
|
+
| `entry` | relative path inside the pack dir, MUST exist (missing entry = instant, nameable refusal - the crashtest#16 lesson is a norm now). "Inside the pack dir" is PHYSICAL, not merely lexical: an entry whose resolved target escapes the pack (via `..`, an absolute path, or a symlink pointing outside) refuses |
|
|
33
28
|
| `armedByKey` | OPTIONAL string. Present: the host MAY run its arming-key ceremony before activation - presence semantics only, so an EMPTY value is "present, not yet armed" (folded from the crashtest#25 matrix fold: the engine treats empty as valid, so a non-empty rule would be a check the SPEC never promised). Absent: the host's own default lifecycle governs |
|
|
34
29
|
|
|
35
|
-
**
|
|
36
|
-
|
|
37
|
-
carry their own optional manifest keys with host-side shape validation. For
|
|
38
|
-
v1, three are acknowledged by name because crashtest's loader already
|
|
39
|
-
validates them (ruled on crashtest#19):
|
|
30
|
+
**Lint-assist key.** `armedCoverage` (added v1.1.0, section 8 row 6) is OPTIONAL: a pack's own declaration of the relative path to its armed end-to-end row - the test that runs the pack against a stub target with its vocabulary armed. It is NOT a shared fact: no conforming loader assigns it meaning. It exists for `packstruct lint`, which CONFIRMS the declared file ships inside the pack dir (a declaration naming a missing or escaping path refuses as `armed-coverage` - the vacuous-green class made loud) and never RUNS the row; runs are the host's business. Absent is the quiet default and never colors a verdict (packstruct#27).
|
|
31
|
+
|
|
32
|
+
**Host-owned acknowledged keys.** The table above is the shared-facts column: fields every conforming loader assigns meaning to. Some hosts additionally carry their own optional manifest keys with host-side shape validation. For v1, three are acknowledged by name because crashtest's loader already validates them (ruled on crashtest#19); a fourth joined in v1.1.0 (section 8 row 1):
|
|
40
33
|
|
|
41
34
|
- `env` - the env-claims block (`d1`/`kv`/`routes`, plus optional `env.seed`)
|
|
42
35
|
- `plugins` - bundled plugin imports, resolved against the pack dir
|
|
43
36
|
- `package` - optional npm name for the pack
|
|
37
|
+
- `implements` - optional string acknowledging the spec the pack builds against, formatted `packstruct@<MAJOR>` or an exact pin `packstruct@1.0.0` (added v1.1.0, section 8 row 1). `packstruct lint` validates FORMAT ONLY and reports a non-conforming shape as a WARNING, never a refusal; absence is the quiet default and never colors a verdict.
|
|
44
38
|
|
|
45
|
-
These are **acknowledged, not shared facts**: the spec documents that they
|
|
46
|
-
may appear and that the HOST owns their semantics and shape rules. Their
|
|
47
|
-
presence is never a spec violation, `packstruct lint` must never refuse a
|
|
48
|
-
pack for carrying them, and a future host naming a fourth host-owned key
|
|
49
|
-
extends this list in a patch revision, not a schemaVersion bump.
|
|
39
|
+
These are **acknowledged, not shared facts**: the spec documents that they may appear and that the HOST owns their semantics and shape rules. Their presence is never a spec violation, `packstruct lint` must never refuse a pack for carrying them, and a future host naming a fourth host-owned key extends this list in a patch revision, not a schemaVersion bump.
|
|
50
40
|
|
|
51
|
-
Extra manifest keys and extra files beside the entry are allowed as
|
|
52
|
-
minimum-spec (the loader assigns no shared meaning to undeclared keys; e.g.
|
|
53
|
-
crashtest's cve-feed ships a snapshot.json beside its entry, which is fine).
|
|
41
|
+
Extra manifest keys and extra files beside the entry are allowed as minimum-spec (the loader assigns no shared meaning to undeclared keys; e.g. crashtest's cve-feed ships a snapshot.json beside its entry, which is fine).
|
|
54
42
|
|
|
55
|
-
**Receipts per frozen row** (added per dhaupin/packstruct#4: every row cites
|
|
56
|
-
the engine evidence it mirrors, so "conforming to spec" and "what this one
|
|
57
|
-
repo does" never blur). Engine rows are from crashtest `fc93ca6`,
|
|
58
|
-
`src/packs/loader.js` - the packstruct#19-audited tree:
|
|
43
|
+
**Receipts per frozen row** (added per dhaupin/packstruct#4: every row cites the engine evidence it mirrors, so "conforming to spec" and "what this one repo does" never blur). Engine rows are from crashtest `fc93ca6`, `src/packs/loader.js` - the packstruct#19-audited tree:
|
|
59
44
|
|
|
60
|
-
- `schemaVersion` MUST be `1` — enforced: `loader.js:77-78` (unsupported
|
|
61
|
-
schemaVersion throws, "have: 1").
|
|
45
|
+
- `schemaVersion` MUST be `1` — enforced: `loader.js:77-78` (unsupported schemaVersion throws, "have: 1").
|
|
62
46
|
- `name` kebab-case — enforced: `loader.js:98` throws on non-kebab names.
|
|
63
|
-
- `name` MUST match its directory — the engine's narrower shape: packs are
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
-
|
|
70
|
-
and a declared file that doesn't ship fails at import with a one-line,
|
|
71
|
-
nameable error naming the pack (`loader.js:394-396`) — the crashtest#16
|
|
72
|
-
class, a norm either way. The linter runs the detection at author time via
|
|
73
|
-
file existence, so a broken manifest refuses before any host loads it.
|
|
74
|
-
- `version` dotted semver-ish — pack-owned semver; the manifest reality is
|
|
75
|
-
the 8/8 #19 audit (every pack ships it), and the version is decoupled from
|
|
76
|
-
every host's and from packstruct's own release cadence (see section 6).
|
|
77
|
-
- `description` non-empty — enforced: `loader.js:59, :71-73`
|
|
78
|
-
(REQUIRED_KEYS throws on missing fields).
|
|
79
|
-
- `armedByKey` optional — engine shape contract: absent = unarmed-but-loadable
|
|
80
|
-
(crashtest#19 ruling folded into the table).
|
|
81
|
-
- Host-owned `env`/`plugins`/`package` — acknowledged and shape-validated:
|
|
82
|
-
`loader.js:24-35` (comment block), `:110` (validateEnvClaims),
|
|
83
|
-
`:398-401` (bundled plugin imports), `:363-364` (seed passthrough).
|
|
84
|
-
- Id collisions refuse at load — enforced: `loader.js:389-391` (shared
|
|
85
|
-
`seen` across surfaces: one loud error naming both origins).
|
|
47
|
+
- `name` MUST match its directory — the engine's narrower shape: packs are loaded FROM their directories and the shared `seen` map keys identity by manifest name (`loader.js:372, :389-391`), so a name/dir disagreement surfaces as a loud collision or misattribution, never silent success. The linter deliberately enforces the stricter contract (name == dir) at author time; engine parity is tracked in dhaupin/packstruct#2.
|
|
48
|
+
- `entry` MUST exist — the engine admits a default entry (`loader.js:101`) and a declared file that doesn't ship fails at import with a one-line, nameable error naming the pack (`loader.js:394-396`) — the crashtest#16 class, a norm either way. The linter runs the detection at author time via file existence, so a broken manifest refuses before any host loads it.
|
|
49
|
+
- `version` dotted semver-ish — pack-owned semver; the manifest reality is the 8/8 #19 audit (every pack ships it), and the version is decoupled from every host's and from packstruct's own release cadence (see section 6).
|
|
50
|
+
- `description` non-empty — enforced: `loader.js:59, :71-73` (REQUIRED_KEYS throws on missing fields).
|
|
51
|
+
- `armedByKey` optional — engine shape contract: absent = unarmed-but-loadable (crashtest#19 ruling folded into the table).
|
|
52
|
+
- Host-owned `env`/`plugins`/`package` — acknowledged and shape-validated: `loader.js:24-35` (comment block), `:110` (validateEnvClaims), `:398-401` (bundled plugin imports), `:363-364` (seed passthrough).
|
|
53
|
+
- Id collisions refuse at load — enforced: `loader.js:389-391` (shared `seen` across surfaces: one loud error naming both origins).
|
|
86
54
|
|
|
87
55
|
## 3. Entry profiles (per host, declared here)
|
|
88
56
|
|
|
89
|
-
An entry is an ES module with a default export. The manifest/dir/entry surface
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
- **`
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
hostile scenarios executed against a transport; hosts of this profile
|
|
96
|
-
provide isolation (fake transport, opt-out postures) and support the
|
|
97
|
-
`armedByKey` ceremony. The module-shape contract is HOST-OWNED in full:
|
|
98
|
-
it lives with the host (crashtest's `reference/scenario-contract`);
|
|
99
|
-
`profiles/scenario.md` links to it rather than copying it - doc drift is
|
|
100
|
-
worse than indirection (ruled on crashtest#19; the `register(ctx)` shape
|
|
101
|
-
in earlier drafts of this section was stale, deleted against the engine
|
|
102
|
-
truth at `fc93ca6` per the engine-first rule). The canonical profile
|
|
103
|
-
pages live with the spec (one address, same ruling):
|
|
104
|
-
`profiles/scenario.md` and `profiles/check.md`.
|
|
105
|
-
- **`check` profile (poststruct):** default export = `{ checks: [Check] }`.
|
|
106
|
-
Declarative pure-reading verifiers over files on disk. No transport, no
|
|
107
|
-
network by default. Arming defaults to config enumeration: being listed in
|
|
108
|
-
the host's `packs:` config IS the arm; no separate key ceremony.
|
|
109
|
-
|
|
110
|
-
A host declares which profile(s) it loads. A pack never changes its own
|
|
111
|
-
semantics based on the host.
|
|
57
|
+
An entry is an ES module with a default export. The manifest/dir/entry surface never forks between hosts; execution semantics are declared as profiles:
|
|
58
|
+
|
|
59
|
+
- **`scenario` profile (crashtest):** default export = a module object carrying `name`, `description`, and an `attacks[]` array (attack names kebab-case, each with a `run` function or a `steps` chain). Contains hostile scenarios executed against a transport; hosts of this profile provide isolation (fake transport, opt-out postures) and support the `armedByKey` ceremony. The module-shape contract is HOST-OWNED in full: it lives with the host (crashtest's `reference/scenario-contract`); `profiles/scenario.md` links to it rather than copying it - doc drift is worse than indirection (ruled on crashtest#19; the `register(ctx)` shape in earlier drafts of this section was stale, deleted against the engine truth at `fc93ca6` per the engine-first rule). The canonical profile pages live with the spec (one address, same ruling): `profiles/scenario.md` and `profiles/check.md`.
|
|
60
|
+
- **`check` profile (poststruct):** default export = `{ checks: [Check] }`. Declarative pure-reading verifiers over files on disk. No transport, no network by default. Arming defaults to config enumeration: being listed in the host's `packs:` config IS the arm; no separate key ceremony.
|
|
61
|
+
|
|
62
|
+
A host declares which profile(s) it loads. A pack never changes its own semantics based on the host.
|
|
112
63
|
|
|
113
64
|
## 4. Lifecycle norms (all hosts)
|
|
114
65
|
|
|
115
|
-
- **Explicit loads only.** A pack runs because the host's config enumerates
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
- **Namespaced ids.** Pack check/scenario ids live in a pack-slug namespace
|
|
119
|
-
in the host's id space. Cross-namespace collision at load time = refuse to
|
|
120
|
-
start, never silent dedupe.
|
|
121
|
-
- **Self-audit fixtures.** Every pack ships `test/fixtures/` proving its
|
|
122
|
-
contents do what they claim. A pack whose fixtures fail fails its own CI
|
|
123
|
-
host-first. (Crashtest backfill note: fixtures are the one norm its
|
|
124
|
-
production packs do not ship yet; it is a lifecycle requirement, not a
|
|
125
|
-
manifest field, so schemaVersion does not move for it.)
|
|
66
|
+
- **Explicit loads only.** A pack runs because the host's config enumerates it. Remote/npm sources are NOT part of v1; adding them requires an explicit spec version bump and stays no-auto-download.
|
|
67
|
+
- **Namespaced ids.** Pack check/scenario ids live in a pack-slug namespace in the host's id space. Cross-namespace collision at load time = refuse to start, never silent dedupe.
|
|
68
|
+
- **Self-audit fixtures.** Every pack ships `test/fixtures/` proving its contents do what they claim. A pack whose fixtures fail fails its own CI host-first. (Crashtest backfill note: fixtures are the one norm its production packs do not ship yet; it is a lifecycle requirement, not a manifest field, so schemaVersion does not move for it.)
|
|
126
69
|
|
|
127
70
|
## 5. Errors (nameable, instant)
|
|
128
71
|
|
|
129
|
-
A conforming loader refuses with a one-line error naming the pack and the
|
|
130
|
-
broken norm the moment it sees the violation: wrong schemaVersion, name/dir
|
|
131
|
-
mismatch, missing entry file, id collision. Never a deep stack trace and
|
|
132
|
-
never silent success.
|
|
72
|
+
A conforming loader refuses with a one-line error naming the pack and the broken norm the moment it sees the violation: wrong schemaVersion, name/dir mismatch, missing entry file, id collision. Never a deep stack trace and never silent success.
|
|
133
73
|
|
|
134
74
|
## 6. Versioning
|
|
135
75
|
|
|
136
|
-
- Additive-first: v2 adds optional manifest fields; removing/renaming is a
|
|
137
|
-
major spec bump requiring a migration note.
|
|
76
|
+
- Additive-first: v2 adds optional manifest fields; removing/renaming is a major spec bump requiring a migration note.
|
|
138
77
|
- Hosts pin the spec they implement (`implements: packstruct@1` in host docs).
|
|
139
|
-
- **Pack version is the pack's own semver, decoupled from every other release
|
|
140
|
-
|
|
141
|
-
changes - not when packstruct ships a new linter, not when a consumer ships
|
|
142
|
-
a new CLI or spec revision. House policy verbatim from crashtest's
|
|
143
|
-
AGENTS.md (where it is enforced by the governance suite): pack manifests
|
|
144
|
-
carry their own semver - never bump those for CLI-level releases. The
|
|
145
|
-
shipped-stable pack keeps its shape: a consumer adopting a newer linter or
|
|
146
|
-
a newer consumer build does not re-roll packs it already froze.
|
|
147
|
-
- **Spec ↔ tool decoupling is the mirror image:** packstruct's own version
|
|
148
|
-
(0.9.x manual, 1.0.0 OIDC per its DEPLOY.md) tracks the linter and harness
|
|
149
|
-
surface only. A lint release that adds checks under the same frozen schema
|
|
150
|
-
is a TOOL semver bump that leaves this document's v1 number alone.
|
|
78
|
+
- **Pack version is the pack's own semver, decoupled from every other release cadence.** A `pack.json` `version` bumps only when that pack's own surface changes - not when packstruct ships a new linter, not when a consumer ships a new CLI or spec revision. House policy verbatim from crashtest's AGENTS.md (where it is enforced by the governance suite): pack manifests carry their own semver - never bump those for CLI-level releases. The shipped-stable pack keeps its shape: a consumer adopting a newer linter or a newer consumer build does not re-roll packs it already froze.
|
|
79
|
+
- **Spec ↔ tool decoupling is the mirror image:** packstruct's own version (0.9.x manual, 1.0.0 OIDC per its DEPLOY.md) tracks the linter and harness surface only. A lint release that adds checks under the same frozen schema is a TOOL semver bump that leaves this document's v1 number alone.
|
|
151
80
|
|
|
152
81
|
## 7. Conformance tooling
|
|
153
82
|
|
|
154
|
-
- `packstruct lint <packs-dir>`: manifest validation + entry existence +
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
83
|
+
- `packstruct lint <packs-dir>`: manifest validation + entry existence + name/dir match (section 2, plus directory-contract checks from section 1). Exit 0 conforming / 1 violations / 2 usage error.
|
|
84
|
+
- `packstruct lint <packs-dir> --deep`: the same shallow pass, plus the section-3/4/5 norms at author time - import each declared entry in an isolated child (an entry that fails to import or carries no default export refuses as `entry-import`/`entry-default-export`) and census the declared ids (a duplicate within a pack, a cross-pack name/id collision, or a collision against a `--against <lib>` host library refuses as `id-duplicate`/`id-collision`/`id-library-collision`). These are the spec's own load-time refusals surfaced early, never new norms; a hostile entry is killed on a timeout or output cap and refused nameably, never run in the linter's own process.
|
|
85
|
+
- `packstruct audit-conformance <repo-dir> --loader "<cmd> {packs}"`: the conformance harness. Bundled verdict-claiming cases (one clean bundle, one per section-5 refusal norm, plus a name-collision pair, plus one `env-claims` bundle carrying the section-2 host-owned `env` block) are materialized into scratch roots and the HOST's own loader command runs over each. A conforming loader exits 0 on the clean bundle and exits non-zero AND names the offending pack on every violation bundle (section 5: nameable refusals; identity matches, refusal wording stays host-owned). The `env-claims` bundle is an ACCEPT case: a pack that merely declares claims is conforming, so a loader must never refuse it. `--claims` additionally requires the loader to ECHO the declared block (one `packstruct:env-claims <claims-json>` stdout line) on that case - a loader that silently ignores `env` is named instead of passing, and one that refuses the spec'd key is named as such (packstruct#71). Same exit ladder: 0 all cases honored / 1 any case failed / 2 usage.
|
|
86
|
+
|
|
87
|
+
## 8. v1.1.0 - the additive rows (adopted 2026-10-29)
|
|
88
|
+
|
|
89
|
+
Six rows, each citing an ENGINE receipt, none moving `schemaVersion` and none changing a conforming host's behavior. Full proposal (byte-pinned at `dd05454` in dhaupin/gistory): `labs/` receipts and issue dhaupin/packstruct#19.
|
|
90
|
+
|
|
91
|
+
1. **`implements`** - the optional host-owned acknowledgement key (section 2). FORMAT ONLY: `packstruct@<MAJOR>` or an exact pin `packstruct@1.0.0`; a non-conforming shape is a lint WARNING, never a refusal; absence is the quiet default. Receipt: eyestruct and poststruct both carry `packstruct@1.0.0` as an exact devDependency, so the pin discipline exists but had no manifest surface.
|
|
92
|
+
2. **The `--loader` template contract, formalized.** `{packs}` substitutes the materialized case pack's DIRECTORY path (never a tarball, never a URL). The loader command runs with CWD = the audited repo root. Exit contract: 0 on the clean bundle; non-zero AND a stderr line naming the offending pack on every violation bundle. The loader runs with NO network and NO implicit host config. A loader that TIMES OUT or crashes is verdict "1 any case failed", never 0, and the harness names which loader failed. Receipt: both live harnesses (poststruct's `run-packs.mjs`, eyestruct's `run-packs.cjs`) hold every clause.
|
|
93
|
+
3. **ESM-default entries, stated plainly.** The entry's DEFAULT EXPORT is the loaded thing. The module format (ESM `export default` / CJS `module.exports`) is the pack's own concern; a loader per-profile decides what run/execute shape it accepts on that default. Receipt: the audit accepted eyestruct's and poststruct's CJS-default fixtures as CORRECT, not as exceptions.
|
|
94
|
+
4. **Interop routes are a LIFECYCLE NORM, not a manifest field.** A pack MAY declare an interop route (run a sibling leg's gate, fork work to a sibling CLI, consume a sibling's runtime) ONLY through the sibling's public CLI surfaces - never by import, and never by guessing a path when an `npx` resolution is available. Receipt: poststruct's `eyes-reference` routes SVG verification through eyestruct's raster gate by invoking eyestruct the TOOL.
|
|
95
|
+
5. **Companion-pin receipts.** Hosts carry the packstruct pin they conform to as an EXACT devDependency, bumped deliberately and receipted per host. A host may lag another host's pin; its `implements` row and CI battery reveal the state. Nothing forces synced bumps - it forces the SYNCHRONIZED RECEIPT when a bump happens.
|
|
96
|
+
6. **`armedCoverage` - the pack-lane coverage declaration (section 2).** OPTIONAL string: the relative path to the pack's armed end-to-end row. `packstruct lint` CONFIRMS the declared file ships inside the pack dir (a declaration naming a missing or escaping path refuses as `armed-coverage` - the vacuous-green class made loud); it never RUNS the row. Absent is the quiet default and never colors a verdict. Receipt: packstruct#27 - crashtest walk rounds 18-20 found pack defects invisible to shape lint (oracle bugs that only fire on a real wire), so the row exists to make "declared armed coverage that isn't there" nameable at author time. This row makes SPEC §2 promise the `armed-coverage` refusal `src/lint.mjs` already emitted - before it, the linter shipped a check the SPEC never promised.
|
|
97
|
+
|
|
98
|
+
## 9. The walk-exit (promotion) rule (v1.1.0)
|
|
99
|
+
|
|
100
|
+
A manual walk is not done until nothing it found is uncommissioned: a walk is not finished while any finding it produced is still unrecorded. Every finding must be promoted, in the same session that found it, to one of:
|
|
101
|
+
|
|
102
|
+
- a battery leg (an executable test that would catch the class again), or
|
|
103
|
+
- a pack verdict row (a case the lint or a host's own suite now grades), or
|
|
104
|
+
- a named docket row (a filed issue carrying the finding).
|
|
105
|
+
|
|
106
|
+
The failure mode this closes is the one-mortem: a probe that got described in prose and never encoded is re-discovered by the next walk. Walks DISCOVER classes; packs REMEMBER them. Neither rung substitutes for the other, and the join between them is this rule. Receipt: eyestruct's walk round landed its serve-dist HTTP-shape proofs and the lint-packs exit-fidelity leg in the same session as the findings (eyestruct `9983b4f`).
|
|
107
|
+
|
|
108
|
+
## 10. Onboarding a new host (the profiles-not-forks example)
|
|
109
|
+
|
|
110
|
+
A new engine ("traveler") joins the grammar by answering the three questions this spec already structures, in this order - never by forking the manifest:
|
|
111
|
+
|
|
112
|
+
1. **What does the manifest see?** The frozen v1 field table (section 2) and the host-owned acknowledged keys (`env`, `plugins`, `package`, `implements`). Nothing to fork; nothing to re-declare.
|
|
113
|
+
2. **What does the lint see?** The same `packstruct lint` / `audit-conformance` lanes. A new profile only extends the CASES it reports, never the manifest grammar. All profile-bearing engines to date gate clean through the same packstruct@1 lane.
|
|
114
|
+
3. **What does run mean?** This is the only new thing a traveler owns: a profile row (execution semantics declared by the host), an engine receipt per adopted behavior, and cases in `audit-conformance` keyed to its profile id.
|
|
115
|
+
|
|
116
|
+
A traveler inherits the standing refusals unchanged: no remote packs, no runs inside lint, no `schemaVersion` bump for additive rows, exact-pin companion receipts.
|
|
117
|
+
|
|
118
|
+
## 11. The MIGRATION-NOTE convention
|
|
119
|
+
|
|
120
|
+
Section 6 promises a migration note for non-additive changes; this section defines its shape BEFORE first need, so every host does not improvise its own answer under pressure. A non-additive change to any family artifact schema (the pack manifest, the lint/audit JSON shapes, host ledger/report artifacts, conformance case packs) MUST carry ALL of:
|
|
121
|
+
|
|
122
|
+
1. **A schema-number bump on the owning artifact** - major on removal/renaming/semantic shift (section 6); additive rows stay same-schema forever.
|
|
123
|
+
2. **A MIGRATIONS row** - one durable file per owning repo (`MIGRATIONS.md` or a spec section), one row per event: what changed, old shape, new shape, refusal wording.
|
|
124
|
+
3. **Refusal wording on old shapes, at the loader/lint** - the mismatch names the schema version it has and the migration row it maps to. Receipt: crashtest's `validatePackManifest` already emits `unsupported schemaVersion N (have: 1)`.
|
|
125
|
+
4. **A dual-read window ONLY where a host owns the artifact** (host configs, host ledgers). NEVER for pack manifests: a manifest is either current or refused loudly - it is a reviewable artifact, not a moving target.
|
|
126
|
+
5. **Consumer receipts** - every companion-pin host that consumes the changed artifact adds its bump row (the section-8-row-5 discipline applied to non-additive events).
|
|
127
|
+
|
|
128
|
+
Explicitly not proposed: no migration EXECUTION at load time (a loader either reads a shape or refuses; transforming on the fly hides the break this convention exists to name), and no new fields on `pack.json` (the note lives in prose/artifacts, not on the frozen field table).
|
package/src/audit.mjs
CHANGED
|
@@ -30,6 +30,16 @@ export const AUDIT_MAXBUFFER_BYTES = 1024 * 1024
|
|
|
30
30
|
|
|
31
31
|
export const CASES_DIR = fileURLToPath(new URL('../conformance/cases/', import.meta.url))
|
|
32
32
|
|
|
33
|
+
// Cases that carry the host-owned `env` claims block and exist to prove a
|
|
34
|
+
// loader does not REFUSE a spec'd key (SPEC section 2). They are accept
|
|
35
|
+
// cases by default; with --claims the loader must instead ECHO the declared
|
|
36
|
+
// claims (SPEC section 2: the host owns env semantics), so the block is
|
|
37
|
+
// exercised, not merely tolerated. A loader that silently ignores `env`
|
|
38
|
+
// passes the default audit and fails --claims - the undogfooded-block class
|
|
39
|
+
// packstruct#71 exists to name.
|
|
40
|
+
export const ENV_CLAIM_CASES = new Set(['env-claims'])
|
|
41
|
+
const CLAIM_MARKER = 'packstruct:env-claims '
|
|
42
|
+
|
|
33
43
|
// The bundled cases: <case>/public/<pack-dir>/, each with a verdict claim.
|
|
34
44
|
// clean expects exit 0; every other case expects a refusing loader.
|
|
35
45
|
export function listCases() {
|
|
@@ -38,6 +48,35 @@ export function listCases() {
|
|
|
38
48
|
})
|
|
39
49
|
}
|
|
40
50
|
|
|
51
|
+
// The declared env claims a case ships, read straight from the manifest - the
|
|
52
|
+
// audit asserts the loader echoes THESE, so the expectation derives from the
|
|
53
|
+
// fixture, never a hand copy.
|
|
54
|
+
export function caseEnvClaims(root) {
|
|
55
|
+
const publicDir = join(root, 'public')
|
|
56
|
+
if (!existsSync(publicDir)) return null
|
|
57
|
+
for (const dir of readdirSync(publicDir)) {
|
|
58
|
+
try {
|
|
59
|
+
const m = JSON.parse(readFileSync(join(publicDir, dir, 'pack.json'), 'utf8'))
|
|
60
|
+
if (m && typeof m === 'object' && m.env && typeof m.env === 'object') return m.env
|
|
61
|
+
} catch { /* a manifest that does not parse is the case's own problem */ }
|
|
62
|
+
}
|
|
63
|
+
return null
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Canonicalize a claims object to a comparable form (sorted keys, sorted
|
|
67
|
+
// arrays) so the echo check matches CONTENT, not key order - a loader that
|
|
68
|
+
// normalizes differently is still honoring the block.
|
|
69
|
+
function canonicalClaims(claims) {
|
|
70
|
+
if (claims === null || claims === undefined) return null
|
|
71
|
+
if (Array.isArray(claims)) return [...claims].map(canonicalClaims).sort()
|
|
72
|
+
if (typeof claims === 'object') {
|
|
73
|
+
const out = {}
|
|
74
|
+
for (const k of Object.keys(claims).sort()) out[k] = canonicalClaims(claims[k])
|
|
75
|
+
return out
|
|
76
|
+
}
|
|
77
|
+
return claims
|
|
78
|
+
}
|
|
79
|
+
|
|
41
80
|
// Pack identities a case's output must name on refusal: the pack directory
|
|
42
81
|
// names and the manifest `name` values (either counts - SPEC section 5 says
|
|
43
82
|
// "naming the pack", the host may identify by dir or manifest name).
|
|
@@ -59,12 +98,17 @@ export async function auditConformance(opts = {}) {
|
|
|
59
98
|
if (typeof opts.loader !== 'string' || !opts.loader.includes('{packs}')) {
|
|
60
99
|
return { caseCount: 0, honored: 0, violations: [{ pack: 'usage', norm: 'usage', message: 'audit-conformance needs --loader "<cmd> {packs}" - {packs} is replaced by each materialized bundle root' }] }
|
|
61
100
|
}
|
|
101
|
+
const claims = opts.claims === true
|
|
62
102
|
const repo = resolve(opts.repo ?? '.')
|
|
63
103
|
const cases = listCases()
|
|
64
104
|
const violations = []
|
|
65
105
|
let honored = 0
|
|
66
106
|
for (const c of cases) {
|
|
67
|
-
|
|
107
|
+
// Accept cases: the clean bundle and the env-claims bundle (a pack that
|
|
108
|
+
// merely carries the spec-allowed `env` block is conforming - SPEC
|
|
109
|
+
// section 2). Every other case claims a refusal.
|
|
110
|
+
const acceptCase = c === 'clean' || ENV_CLAIM_CASES.has(c)
|
|
111
|
+
const expect = acceptCase ? 'accept' : 'refuse'
|
|
68
112
|
const tmp = mkdtempSync(join(tmpdir(), 'packstruct-audit-'))
|
|
69
113
|
try {
|
|
70
114
|
cpSync(join(CASES_DIR, c), tmp, { recursive: true })
|
|
@@ -84,7 +128,36 @@ export async function auditConformance(opts = {}) {
|
|
|
84
128
|
why = `loader hung past the audit timeout (${auditTimeoutMs}ms, killed with ${r.signal ?? 'SIGKILL'}) - writes no verdict; a refusal is instant, hangs are neither accept nor refuse`
|
|
85
129
|
} else {
|
|
86
130
|
const claimed = r.status === 0
|
|
87
|
-
if (
|
|
131
|
+
if (claims && ENV_CLAIM_CASES.has(c)) {
|
|
132
|
+
// The claims probe: the loader must ACCEPT and ECHO the declared
|
|
133
|
+
// block. Refusing it is the "spec'd key a loader rejects" defect;
|
|
134
|
+
// accepting without echoing is the silent-ignore defect. Both name
|
|
135
|
+
// the case - a loader must prove it carries the claims, not that
|
|
136
|
+
// it can look away.
|
|
137
|
+
const want = caseEnvClaims(tmp)
|
|
138
|
+
if (!claimed) {
|
|
139
|
+
ok = false
|
|
140
|
+
why = 'refused a pack carrying the spec-allowed `env` block (SPEC section 2: host-owned, never a refusal)'
|
|
141
|
+
} else {
|
|
142
|
+
const line = out.split(/\r?\n/).find(l => l.startsWith(CLAIM_MARKER))
|
|
143
|
+
if (!line) {
|
|
144
|
+
ok = false
|
|
145
|
+
why = `accepted but did not echo the declared env claims - emit a line "${CLAIM_MARKER}<claims-json>" carrying the block it honored (a loader that silently ignores env passes the default audit; --claims is the leg that catches it)`
|
|
146
|
+
} else {
|
|
147
|
+
let echoed = null
|
|
148
|
+
try { echoed = JSON.parse(line.slice(CLAIM_MARKER.length)) } catch { echoed = undefined }
|
|
149
|
+
if (echoed === undefined) {
|
|
150
|
+
ok = false
|
|
151
|
+
why = `echoed env claims were not parseable JSON after "${CLAIM_MARKER}"`
|
|
152
|
+
} else if (JSON.stringify(canonicalClaims(echoed)) !== JSON.stringify(canonicalClaims(want))) {
|
|
153
|
+
ok = false
|
|
154
|
+
why = `echoed env claims do not match the manifest - declared ${JSON.stringify(want)}, echoed ${JSON.stringify(echoed)}`
|
|
155
|
+
} else {
|
|
156
|
+
ok = true
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
} else if (expect === 'accept') {
|
|
88
161
|
ok = claimed
|
|
89
162
|
} else {
|
|
90
163
|
ok = !claimed
|