packstruct 1.1.1 → 1.1.3

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 CHANGED
@@ -1,4 +1,4 @@
1
- # packstruct 1.1.1
1
+ # packstruct 1.1.3
2
2
 
3
3
  The shared `/packs` spec. **One manifest + entry + lifecycle contract, many hosts**: [crashtest](https://github.com/dhaupin/crashtest) (scenario), [poststruct](https://github.com/dhaupin/poststruct) (check), plus two profiles bound to the host-owned [memstruct](https://github.com/dhaupin/memstruct) standard - [`memory`](profiles/memory.md) (vant's markdown store) and [`sync`](profiles/sync.md) (gistory's merge).
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "packstruct",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "The shared /packs spec: one manifest, entry, and lifecycle contract for crashtest and poststruct packs - plus a zero-dependency lint CLI that kills broken pack manifests at author time.",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -18,10 +18,11 @@
18
18
  "spec/",
19
19
  "profiles/",
20
20
  "conformance/",
21
+ "packs/",
21
22
  "LICENSE"
22
23
  ],
23
24
  "scripts": {
24
- "test": "node test/run.mjs && node --test test/status.test.mjs test/refusal-matrix.test.mjs test/run-capped.test.mjs tests/ship-from-download.test.cjs tests/release-verify.test.cjs tests/check-action-pins.test.cjs && node --test tests/check-prestruct-pins.test.cjs",
25
+ "test": "node test/run.mjs && node --test test/status.test.mjs test/refusal-matrix.test.mjs test/deep-probe-cwd.test.mjs test/run-capped.test.mjs tests/ship-from-download.test.cjs tests/release-verify.test.cjs tests/post-permalinks.test.cjs tests/distribution.test.cjs tests/check-action-pins.test.cjs tests/npm-parity.test.cjs && node --test tests/check-prestruct-pins.test.cjs",
25
26
  "test:ship": "node --test tests/ship-from-download.test.cjs",
26
27
  "lint:docs": "node scripts/check-docs-frontmatter.cjs && node scripts/check-docs-links.cjs && node scripts/check-docs-style.cjs && node scripts/check-jekyll-filters.cjs && node scripts/check-language.cjs",
27
28
  "lint:pins": "node scripts/check-action-pins.cjs",
@@ -0,0 +1,206 @@
1
+ // packs/public/packstruct-lint-shapes/index.js - the packstruct lint lane.
2
+ //
3
+ // The real component under attack: the lint CLI's contract per SPEC v1
4
+ // section 5 - "a conforming loader refuses with a one-line error naming the
5
+ // pack and the broken norm the moment it sees the violation... Never a deep
6
+ // stack trace and never silent success." The transport is an in-process
7
+ // double (crashtest.config.js) that materializes one hostile pack.json per
8
+ // request into a temp dir and runs `node bin/cli.mjs lint <dir> --json` as
9
+ // a subprocess - the same wire a user and CI consume.
10
+ //
11
+ // Cross-repo pack doctrine (prestruct-proxy / freestruct-docs-shapes
12
+ // precedent): NO imports from crashtest internals. Plain verdict records,
13
+ // honest skips - a shape the run root cannot support is a REFUSED posture
14
+ // note, never a fake verdict.
15
+ //
16
+ // Four attacks, one contract each:
17
+ //
18
+ // hostile-manifest-fuzz every malformed pack.json (bad JSON, wrong
19
+ // types every field, deep-nest bomb, huge
20
+ // strings) answers in-bounds: JSON verdict
21
+ // body, violations[] with named packs/norms,
22
+ // exit 0 or 1 - never 5xx, never a throw.
23
+ // entry-path-containment entry values that escape the pack dir
24
+ // (path traversal, absolute paths, file URLs)
25
+ // are flagged by the deterministic 'entry'
26
+ // norm - never accepted as "exists".
27
+ // over-strict-drift-canary spec-ALLOWED shapes (extra manifest keys,
28
+ // snapshot files beside the entry, unnamed
29
+ // optional absence) exit 0 with zero
30
+ // violations - a lint that flags minimum-spec
31
+ // shapes is itself a regression (SPEC 3.4).
32
+ // clean-pack-canary the conforming fixture pack exits 0 with an
33
+ // empty violations list - the happy wire holds.
34
+ //
35
+ // Vocabulary (ctx / moduleCtx['packstruct-lint-shapes']):
36
+ // route route name of the lint double (default: 'lint')
37
+ //
38
+ const DEFAULT_ROUTE = 'lint';
39
+
40
+ // Hard-named CLI of the tool under test (the honest wire, not library
41
+ // internals): `node bin/cli.mjs lint <dir> --json`.
42
+ const CLI_SPEC = ['bin/cli.mjs', 'lint', '--json'];
43
+
44
+ // Hostile pack.json alphabet. Each shape gets its own pack dir named
45
+ // 'corpus-pack' inside a per-request temp root.
46
+ const HOSTILE_MANIFESTS = {
47
+ 'boom-json': '{ not: valid JSON at all!!!',
48
+ 'wrongtypes': JSON.stringify({
49
+ schemaVersion: '1', name: 123, description: [], version: {}, entry: 42,
50
+ }),
51
+ 'deep-nest': JSON.stringify({ schemaVersion: 1, name: 'corpus-pack', description: 'x', version: '0.1.0', entry: 'e.mjs', extra: (function deep(n) { return n ? [deep(n - 1)] : 'leaf'; })(256) }),
52
+ 'huge-string': JSON.stringify({ schemaVersion: 1, name: 'corpus-pack', description: 'y'.repeat(1024 * 512), version: '0.1.0', entry: 'e.mjs' }),
53
+ };
54
+
55
+ const ENTRY_ESCAPE_MANIFESTS = {
56
+ 'entry-traversal': JSON.stringify({ schemaVersion: 1, name: 'corpus-pack', description: 'hostile', version: '0.1.0', entry: '../../package.json' }),
57
+ 'entry-absolute': JSON.stringify({ schemaVersion: 1, name: 'corpus-pack', description: 'hostile', version: '0.1.0', entry: '/etc/passwd' }),
58
+ // Absolute but resolving inside the pack: the class the substring proxy
59
+ // missed (join re-rooted it, so shallow passed it while deep refused).
60
+ 'entry-absolute-inpack': JSON.stringify({ schemaVersion: 1, name: 'corpus-pack', description: 'hostile', version: '0.1.0', entry: '/e.mjs' }),
61
+ 'entry-dot': JSON.stringify({ schemaVersion: 1, name: 'corpus-pack', description: 'hostile', version: '0.1.0', entry: '.' }),
62
+ 'entry-file-url': JSON.stringify({ schemaVersion: 1, name: 'corpus-pack', description: 'hostile', version: '0.1.0', entry: 'file:///etc/passwd' }),
63
+ 'entry-null-byte': JSON.stringify({ schemaVersion: 1, name: 'corpus-pack', description: 'hostile', version: '0.1.0', entry: 'e.mjs\0/../passwd' }),
64
+ // The entry names a directory (the transport materializes it as one): not
65
+ // an ES module (SPEC 3), so the manifest pass must refuse it, not only deep.
66
+ 'entry-is-directory': JSON.stringify({ schemaVersion: 1, name: 'corpus-pack', description: 'hostile', version: '0.1.0', entry: 'e.mjs' }),
67
+ // The entry is a SYMLINK whose target lives outside the pack: the manifest
68
+ // path is lexically contained, but the physical target escapes. The
69
+ // transport materializes the link; containment must refuse it on the
70
+ // manifest pass, not only when deep imports the outside file.
71
+ 'entry-symlink-escape': JSON.stringify({ schemaVersion: 1, name: 'corpus-pack', description: 'hostile', version: '0.1.0', entry: 'e.mjs' }),
72
+ };
73
+
74
+ // Cross-repo pack doctrine: inline verdict helpers (no crashtest imports).
75
+ const exhausted = (detail, extra = {}) => ({ verdict: 'EXPLOITED', detail, ...extra });
76
+ const refused = (detail, extra = {}) => ({ verdict: 'REFUSED', detail, ...extra });
77
+
78
+ function routeOf(ctx) { return (ctx && ctx.route) || DEFAULT_ROUTE; }
79
+
80
+ /** Truthful lint run: returns { threw?, exit, stdout, stderr } without throwing. */
81
+ async function runLint(harness, route, shape) {
82
+ const rec = await harness.run(route, { method: 'GET', url: `/lint?shape=${shape}` });
83
+ if (rec.threw) return { threw: true, error: rec.error };
84
+ let body = '';
85
+ try { body = await rec.response.text(); } catch { /* empty */ }
86
+ return { threw: false, status: rec.status, body };
87
+ }
88
+
89
+ function parseVerdict(body) {
90
+ try {
91
+ const r = JSON.parse(body); // {exit, stdout, stderr}
92
+ const out = JSON.parse(r.stdout); // {schema, packsChecked, violations}
93
+ if (!Array.isArray(out.violations)) return null;
94
+ return { exit: r.exit, stderr: r.stderr ?? '', violations: out.violations };
95
+ } catch { return null; }
96
+ }
97
+
98
+ const isNameable = (v) => v && typeof v.pack === 'string' && v.pack.length > 0 &&
99
+ typeof v.norm === 'string' && v.norm.length > 0 &&
100
+ typeof v.message === 'string' && v.message.length > 0;
101
+
102
+ const STACK_MARKERS = /(^|\n)\s*at .*\(|^\s*ReferenceError|^\s*TypeError|Uncaught/;
103
+
104
+ export default {
105
+ name: 'packstruct-lint-shapes',
106
+ description: 'hostile-manifest wire truths for packstruct lint: in-bounds refusals under malformed manifests (never crash, never silent success), entry path containment, minimum-spec tolerance (zero dependencies, zero sockets)',
107
+
108
+ attacks: [
109
+ {
110
+ name: 'hostile-manifest-fuzz',
111
+ description: 'every malformed pack.json answers in-bounds: parseable verdict JSON, violations carried with {pack,norm,message}, exit 0/1 - never 5xx, never a deep stack trace',
112
+ async run(harness, ctx = {}) {
113
+ const route = routeOf(ctx);
114
+ const crashes = [];
115
+ const violations = [];
116
+ for (const shape of Object.keys(HOSTILE_MANIFESTS)) {
117
+ const r = await runLint(harness, route, shape);
118
+ if (r.threw) { crashes.push(`${shape}: harness throw`); continue; }
119
+ if (r.status >= 500) { crashes.push(`${shape}: status ${r.status}`); continue; }
120
+ const v = parseVerdict(r.body);
121
+ if (!v) { crashes.push(`${shape}: body is not parseable JSON verdict`); continue; }
122
+ if (v.exit !== 0 && v.exit !== 1) crashes.push(`${shape}: exit ${v.exit}`);
123
+ if (v.stderr && STACK_MARKERS.test(v.stderr)) crashes.push(`${shape}: deep stack trace in stderr`);
124
+ if (!v.violations.every(isNameable)) { violations.push(`${shape}: violation record not nameable`); continue; }
125
+ }
126
+ const fails = [...crashes, ...violations];
127
+ if (fails.length) {
128
+ return exhausted(`lint contract broken under hostile manifest corpus: ${fails.join(' | ')}`);
129
+ }
130
+ return refused(
131
+ `${Object.keys(HOSTILE_MANIFESTS).length} hostile manifest shapes held: in-bounds verdicts, nameable refusals + norms, no crash, no deep stack (SPEC v1 section 5)`,
132
+ { shapes: Object.keys(HOSTILE_MANIFESTS).length },
133
+ );
134
+ },
135
+ },
136
+
137
+ {
138
+ name: 'entry-path-containment',
139
+ description: 'entry values escaping the pack dir (traversal, absolute, file URL, null byte) are flagged by the entry norm - an outside file that happens to exist never silences the refusal',
140
+ async run(harness, ctx = {}) {
141
+ const route = routeOf(ctx);
142
+ const leaks = [];
143
+ const crashes = [];
144
+ for (const shape of Object.keys(ENTRY_ESCAPE_MANIFESTS)) {
145
+ const r = await runLint(harness, route, shape);
146
+ if (r.threw) { crashes.push(shape); continue; }
147
+ const v = parseVerdict(r.body);
148
+ if (!v) { crashes.push(shape); continue; }
149
+ const entryFlag = v.violations.find((x) => x.norm === 'entry');
150
+ if (!entryFlag) {
151
+ leaks.push(`${shape}: entry escape accepted (no entry-norm violation)`);
152
+ continue;
153
+ }
154
+ if (!isNameable(entryFlag)) leaks.push(`${shape}: entry flag not nameable`);
155
+ }
156
+ const fails = [...crashes, ...leaks];
157
+ if (fails.length) {
158
+ return exhausted(`entry containment broken: ${fails.join(' | ')}`);
159
+ }
160
+ return refused(
161
+ `${Object.keys(ENTRY_ESCAPE_MANIFESTS).length} entry-escape shapes held: every escape flagged by the nameable 'entry' norm (the crashtest#16 class, closed at the wire)`,
162
+ { shapes: Object.keys(ENTRY_ESCAPE_MANIFESTS).length },
163
+ );
164
+ },
165
+ },
166
+
167
+ {
168
+ name: 'over-strict-drift-canary',
169
+ description: 'spec-ALLOWED shapes (extra manifest keys, extra files beside the entry) exit 0 with zero violations - over-strict linting of minimum-spec shapes is a lint-side regression (SPEC 3.4)',
170
+ async run(harness, ctx = {}) {
171
+ const route = routeOf(ctx);
172
+ const overStrict = [];
173
+ for (const shape of ['extra-keys', 'extra-files']) {
174
+ const r = await runLint(harness, route, shape);
175
+ if (r.threw) { overStrict.push(`${shape}: harness throw`); continue; }
176
+ const v = parseVerdict(r.body);
177
+ if (!v) { overStrict.push(`${shape}: unparseable verdict`); continue; }
178
+ if (v.exit !== 0 || v.violations.length > 0) {
179
+ overStrict.push(`${shape}: exit ${v.exit}, ${v.violations.length} violation(s)`);
180
+ }
181
+ }
182
+ if (overStrict.length) {
183
+ return exhausted(`spec tolerance broken: ${overStrict.join(' | ')} - the linter flagged shapes SPEC 3.4 explicitly allows`);
184
+ }
185
+ return refused('minimum-spec shapes held: extra manifest keys and extra-files existing beside the entry both exit 0, zero violations (SPEC 3.4 additive-first contract)');
186
+ },
187
+ },
188
+
189
+ {
190
+ name: 'clean-pack-canary',
191
+ description: 'the conforming fixture pack (schemaVersion 1, name/dir match, existing entry) exits 0 with an empty violations list - the happy wire holds',
192
+ async run(harness, ctx = {}) {
193
+ const route = routeOf(ctx);
194
+ const r = await runLint(harness, route, 'clean-pack');
195
+ if (r.threw) return exhausted('clean pack canary crashed the lint double');
196
+ const v = parseVerdict(r.body);
197
+ if (!v) return exhausted('clean pack canary: unparseable verdict body');
198
+ if (v.exit !== 0) return exhausted(`clean pack canary: exit ${v.exit} - conforming shape refused`);
199
+ if (v.violations.length > 0) {
200
+ return exhausted(`clean pack canary flagged: ${JSON.stringify(v.violations.slice(0, 4))}`);
201
+ }
202
+ return refused('clean pack canary held: conforming shape answers exit 0, zero violations - the lint never flags honest packs');
203
+ },
204
+ },
205
+ ],
206
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "name": "packstruct-lint-shapes",
4
+ "description": "Hostile-manifest wire truths for packstruct lint: malformed pack.json never crashes the CLI (refuse, never fail), entry path traversal is contained, and spec-allowed shapes are never over-strictly flagged. Zero dependencies, zero sockets.",
5
+ "version": "0.1.0",
6
+ "entry": "index.js"
7
+ }
package/src/lint.mjs CHANGED
@@ -309,11 +309,18 @@ try {
309
309
  // pipe-EOF that an orphaned grandchild spawned by the entry can hold
310
310
  // forever, and an output-flooding entry hits the 1MB cap (an honest
311
311
  // entry-import refusal), not a scratch-file flood that fills the disk.
312
- async function childProbe(absPath, timeoutMs = PROBE_TIMEOUT_MS) {
312
+ //
313
+ // `cwd` is the host root (the parent of the linted `packs/`), never the
314
+ // caller's cwd. A pack entry is host code and resolves host paths such as
315
+ // `lib/traveler.js` relative to its own repo; inheriting the caller's cwd
316
+ // made the same tree lint clean from inside the host and false-fail with
317
+ // `entry-import` from anywhere else (packstruct#120).
318
+ async function childProbe(absPath, timeoutMs = PROBE_TIMEOUT_MS, cwd) {
313
319
  const fileUrl = pathToFileURL(absPath).href
314
320
  const r = await runCapped({
315
321
  cmd: process.execPath,
316
322
  args: ['--input-type=module', '--no-warnings', '-e', childProbeScript(fileUrl)],
323
+ cwd,
317
324
  timeoutMs,
318
325
  maxBuffer: 1024 * 1024,
319
326
  killSignal: 'SIGKILL',
@@ -340,7 +347,7 @@ async function childProbe(absPath, timeoutMs = PROBE_TIMEOUT_MS) {
340
347
  // in-process (inert data - no code execution needed); code modules are
341
348
  // child-probed one by one, same as pack entries. The library's internal
342
349
  // shapes stay the host's business.
343
- async function collectLibraryUnits(ref, timeoutMs) {
350
+ async function collectLibraryUnits(ref, timeoutMs, cwd) {
344
351
  const units = []
345
352
  if (ref.endsWith('.json')) {
346
353
  const obj = JSON.parse(readFileSync(ref, 'utf8'))
@@ -356,7 +363,7 @@ async function collectLibraryUnits(ref, timeoutMs) {
356
363
  for (const file of files) {
357
364
  let report
358
365
  try {
359
- report = await childProbe(file, timeoutMs)
366
+ report = await childProbe(file, timeoutMs, cwd)
360
367
  } catch (err) {
361
368
  throw new Error(`${file}: ${err.message}`)
362
369
  }
@@ -376,6 +383,10 @@ export async function deepLintPacks(dir, opts = {}) {
376
383
  const warnings = [...(shallow.warnings ?? [])]
377
384
  const localChecked = shallow.localChecked ?? 0
378
385
  const publicDir = join(dir, 'public')
386
+ // The host root every probe runs in: the parent of the linted `packs/`
387
+ // (the same root resolvePacksRoot discovers). Probes are host code and
388
+ // resolve host paths relative to it (packstruct#120).
389
+ const hostRoot = dirname(resolve(dir))
379
390
  let libraryIds = 0
380
391
  if (!existsSync(publicDir)) {
381
392
  return { packsChecked: shallow.packsChecked, localChecked, violations, warnings, modulesProbed: 0, idsCensused: 0, libraryIds }
@@ -392,7 +403,7 @@ export async function deepLintPacks(dir, opts = {}) {
392
403
  // namespaced-ids norm, engine side: the #19 44-vs-49 zero-collision claim).
393
404
  if (opts.against !== undefined) {
394
405
  try {
395
- const lib = await collectLibraryUnits(opts.against, timeoutMs)
406
+ const lib = await collectLibraryUnits(opts.against, timeoutMs, hostRoot)
396
407
  for (const { id, at } of lib) {
397
408
  if (idSeen.has(id)) continue // the library's own internals: not ours to judge
398
409
  idSeen.set(id, { pack: DEEP_LIB_TAG, at: `--against (${at})` })
@@ -428,7 +439,7 @@ export async function deepLintPacks(dir, opts = {}) {
428
439
  if (typeof m.entry !== 'string' || !existsSync(join(packDir, m.entry))) continue
429
440
  let report
430
441
  try {
431
- report = await childProbe(resolve(packDir, m.entry), timeoutMs)
442
+ report = await childProbe(resolve(packDir, m.entry), timeoutMs, hostRoot)
432
443
  } catch (err) {
433
444
  violations.push(tagLane({ pack: name, norm: 'entry-import', message: `entry "${m.entry}": ${err.message}` }, lane))
434
445
  continue