@bongos/core 1.19.305 → 1.19.307

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.
@@ -0,0 +1,168 @@
1
+ // tests/ship_cannot_lie.mjs — G04, task 1003168, goal 1000077, criterion
2
+ // guards-ship-cannot-lie.
3
+ //
4
+ // TWO fixes, one incident, so one test file.
5
+ //
6
+ // (1) Prose reaches ship.js through a FILE, never only through the shell.
7
+ // Backticks in handoff notes are command-substituted by bash BEFORE node
8
+ // runs: the span executes, its output replaces it, and the remaining
9
+ // arguments are truncated. That shipped a task with empty notes and no
10
+ // summary — the ledger recorded nothing about a session that happened
11
+ // (learning 1000197).
12
+ //
13
+ // (2) A ship that dies mid-pipeline must say where it stopped. resolveClaim
14
+ // lands the task at 'completed' before the grade runs, and 'completed' is
15
+ // ALSO what a grade-failed task looks like — so a bare `fatal: <stack>`
16
+ // left nobody able to tell how far it got.
17
+ import { strict as assert } from 'node:assert';
18
+ import { test } from 'node:test';
19
+ import { createRequire } from 'node:module';
20
+
21
+ const require = createRequire(import.meta.url);
22
+ const { argText } = require('../scripts/gds/cli-lib.js');
23
+ const { fatalRecoveryLines, markShipProgress, _peekForTest } = require('../scripts/gds/ship-honesty.js');
24
+
25
+ // Injected IO so no case touches the filesystem.
26
+ const io = {
27
+ readFile: (f) => {
28
+ if (f === 'notes.md') return 'real notes with `backticks` in them';
29
+ if (f === 'bom.md') return 'after a BOM';
30
+ throw new Error('ENOENT: no such file');
31
+ },
32
+ readStdin: () => 'from stdin',
33
+ };
34
+
35
+ // ---- (1) prose from a file -------------------------------------------------
36
+ test('THE INCIDENT: a file argument carries backticks through untouched', () => {
37
+ // The shell never sees this content, so the backticks survive verbatim —
38
+ // that is the entire point of the flag.
39
+ const r = argText('--notes', ['--notes-file', 'notes.md'], io);
40
+ assert.equal(r.source, 'file');
41
+ assert.match(r.value, /`backticks`/);
42
+ assert.equal(r.error, null);
43
+ });
44
+
45
+ test('inline still works, for a short summary with no awkward characters', () => {
46
+ const r = argText('--summary', ['--summary', 'one line'], io);
47
+ assert.deepEqual([r.value, r.source, r.error], ['one line', 'inline', null]);
48
+ });
49
+
50
+ test('BOTH given is REFUSED, never silently resolved', () => {
51
+ // Precedence would mean one of the caller's two inputs vanished with no word
52
+ // said — the same quiet loss the flag exists to end.
53
+ const r = argText('--notes', ['--notes', 'a', '--notes-file', 'notes.md'], io);
54
+ assert.ok(r.error, 'both-given must be an error');
55
+ assert.match(r.error, /both/i);
56
+ assert.equal(r.value, '', 'a refusal must not hand back a half-resolved value');
57
+ });
58
+
59
+ test('a dash reads stdin', () => {
60
+ const r = argText('--notes', ['--notes-file', '-'], io);
61
+ assert.deepEqual([r.value, r.source], ['from stdin', 'stdin']);
62
+ });
63
+
64
+ test('an unreadable file is an error, not silently empty', () => {
65
+ // Silently-empty is precisely how the original incident hid itself.
66
+ const r = argText('--notes', ['--notes-file', 'gone.md'], io);
67
+ assert.ok(r.error);
68
+ assert.match(r.error, /could not read/);
69
+ });
70
+
71
+ test('a missing value for the file flag is caught, including a following flag', () => {
72
+ for (const args of [['--notes-file'], ['--notes-file', '--summary', 'x']]) {
73
+ const r = argText('--notes', args, io);
74
+ assert.ok(r.error, `${JSON.stringify(args)} must error`);
75
+ assert.match(r.error, /needs a path/);
76
+ }
77
+ });
78
+
79
+ test('a PowerShell BOM is stripped', () => {
80
+ // PS 5.1's `>` redirection writes a UTF-8 BOM; without stripping it the first
81
+ // character of every note would be U+FEFF.
82
+ const r = argText('--notes', ['--notes-file', 'bom.md'], io);
83
+ assert.equal(r.value, 'after a BOM');
84
+ });
85
+
86
+ test('neither flag yields empty string, not null — callers concatenate it', () => {
87
+ const r = argText('--notes', [], io);
88
+ assert.deepEqual([r.value, r.source, r.error], ['', 'none', null]);
89
+ });
90
+
91
+ // ---- (2) the ship cannot lie about how far it got --------------------------
92
+ test('every stage names the task, its real status, and a recovery command', () => {
93
+ for (const stage of ['preflight', 'resolved', 'graded', 'landed']) {
94
+ const lines = fatalRecoveryLines({ stage, taskId: 4242 });
95
+ assert.ok(Array.isArray(lines) && lines.length >= 3, `${stage} must say something`);
96
+ for (const l of lines) assert.equal(typeof l, 'string', `${stage} lines are printable as-is`);
97
+ assert.ok(lines.some((l) => l.includes('4242')), `${stage} must name the task`);
98
+ assert.ok(
99
+ lines.some((l) => l.includes('node scripts/gds/ship.js 4242')),
100
+ `${stage} must name the command that recovers it`,
101
+ );
102
+ }
103
+ });
104
+
105
+ test('pre-resolve says the claim is INTACT — the opposite of the post-resolve case', () => {
106
+ const text = fatalRecoveryLines({ stage: 'preflight', taskId: 7 }).join('\n');
107
+ assert.match(text, /NOT resolved/);
108
+ assert.match(text, /still active/);
109
+ });
110
+
111
+ test("post-resolve names 'completed' AND that the grade did not record", () => {
112
+ // The distinction the status itself cannot make.
113
+ const text = fatalRecoveryLines({ stage: 'resolved', taskId: 7 }).join('\n');
114
+ assert.match(text, /'completed'/);
115
+ assert.match(text, /grade did NOT record/);
116
+ assert.match(text, /No credits/i);
117
+ });
118
+
119
+ test("post-grade names 'confirmed' and that the grade PASSED", () => {
120
+ const text = fatalRecoveryLines({ stage: 'graded', taskId: 7 }).join('\n');
121
+ assert.match(text, /'confirmed'/);
122
+ assert.match(text, /PASSED/);
123
+ });
124
+
125
+ test('the landed stage does NOT claim the ship failed', () => {
126
+ // It reached 'shipped'; only the after-work broke. Saying "the ship did not
127
+ // finish" there would be the same lying-status problem in reverse.
128
+ const lines = fatalRecoveryLines({ stage: 'landed', taskId: 7 });
129
+ assert.match(lines[0], /LANDED/);
130
+ assert.ok(!/did NOT finish/.test(lines.join('\n')));
131
+ });
132
+
133
+ test('NO stage recommends --regrade as the recovery', () => {
134
+ // A plain re-run routes by the task's CURRENT status, so it resumes whichever
135
+ // leg stalled. --regrade accepts only 'completed' and refuses a task that got
136
+ // to 'confirmed' — and the builder reading a crash cannot know which it is.
137
+ for (const stage of ['preflight', 'resolved', 'graded', 'landed']) {
138
+ const text = fatalRecoveryLines({ stage, taskId: 7 });
139
+ for (const l of text) {
140
+ assert.ok(
141
+ !/^\s*Resume:?\s+node .*--regrade/.test(l) && !/re-run:\s+node .*--regrade/.test(l),
142
+ `${stage} must not prescribe --regrade: ${l}`,
143
+ );
144
+ }
145
+ }
146
+ });
147
+
148
+ test('an unknown stage degrades to the safe pre-resolve message', () => {
149
+ // A future leg added without a case here must not produce a confident wrong
150
+ // claim about credits or status.
151
+ const text = fatalRecoveryLines({ stage: 'something-new', taskId: 7 }).join('\n');
152
+ assert.match(text, /NOT resolved/);
153
+ });
154
+
155
+ test('a missing taskId still yields a usable command', () => {
156
+ const text = fatalRecoveryLines({ stage: 'resolved', taskId: null }).join('\n');
157
+ assert.match(text, /ship\.js <task-id>/);
158
+ });
159
+
160
+ test('markShipProgress is the single writer, and ship.js re-exports the reader', () => {
161
+ // Wiring proof: the extraction must not have left ship.js reading a stale copy.
162
+ markShipProgress('graded', 99);
163
+ assert.deepEqual(_peekForTest(), { stage: 'graded', taskId: 99 });
164
+ assert.match(fatalRecoveryLines().join('\n'), /#99/, 'the default arg reads live progress');
165
+ const shipCli = require('../scripts/gds/ship.js');
166
+ assert.equal(typeof shipCli.fatalRecoveryLines, 'function', 'ship.js still exposes it');
167
+ assert.equal(shipCli.fatalRecoveryLines, fatalRecoveryLines, 'same function, not a copy');
168
+ });
@@ -14,7 +14,7 @@ import { strict as assert } from 'node:assert';
14
14
  import { createRequire } from 'node:module';
15
15
 
16
16
  const require = createRequire(import.meta.url);
17
- const { smokeGateMessages } = require('../scripts/gds/ship.js');
17
+ const { smokeGateMessages } = require('../scripts/gds/ship-honesty.js');
18
18
 
19
19
  let passed = 0;
20
20
  let failed = 0;
@@ -61,8 +61,14 @@ t('parked: names the deliberate stop, the exact status, and that nothing was pai
61
61
  assert.match(parkedText, /no credits/i);
62
62
  });
63
63
 
64
- t('parked: names the resume path (--regrade)', () => {
65
- assert.match(parkedText, /ship\.js 1234 --regrade/);
64
+ t('parked: names the resume path (a plain re-run, not --regrade)', () => {
65
+ // task 1003168 (G04): this used to say --regrade. A plain re-run routes by the
66
+ // task's CURRENT status, so it resumes whichever leg stalled; --regrade accepts
67
+ // only 'completed' and refuses a task that got as far as 'confirmed'. Since the
68
+ // builder reading this cannot know which leg died, the advice must be the
69
+ // command that works from either.
70
+ assert.match(parkedText, /ship\.js 1234$|ship\.js 1234\s/m);
71
+ assert.ok(!/ship\.js 1234 --regrade/.test(parkedText), 'must not recommend --regrade');
66
72
  });
67
73
 
68
74
  t('both message sets are non-empty arrays of strings (printable as-is)', () => {