harness-everything 1.0.1 → 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.
Files changed (31) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +14 -0
  4. package/ci/mechanism-394-ledger-match.test.js +219 -0
  5. package/ci/mechanism-496-claude-capture.test.js +342 -0
  6. package/ci/mechanism-496-codex-capture.test.js +508 -0
  7. package/ci/mechanism-496-local-error-cli-edges.test.js +234 -0
  8. package/ci/mechanism-496-local-error-cli.test.js +517 -0
  9. package/ci/mechanism-496-local-error-store.test.js +731 -0
  10. package/ci/mechanism-496-opencode-capture.test.js +483 -0
  11. package/ci/mechanism-496-review-fixes.test.js +278 -0
  12. package/hooks/scripts/codex-ledger-lesson.js +103 -27
  13. package/hooks/scripts/ledger-lesson.js +94 -23
  14. package/hooks/scripts/lib/ledger-match.js +39 -3
  15. package/hooks/scripts/lib/local-error-source.js +127 -0
  16. package/hooks/scripts/lib/local-errors.js +597 -0
  17. package/hooks/scripts/lib/observations.js +1 -1
  18. package/opencode-plugin/index.mjs +86 -1
  19. package/opencode-plugin/plugin.json +1 -1
  20. package/package.json +2 -1
  21. package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
  22. package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
  23. package/plugins/harness-everything/hooks/scripts/codex-ledger-lesson.js +103 -27
  24. package/plugins/harness-everything/hooks/scripts/ledger-lesson.js +94 -23
  25. package/plugins/harness-everything/hooks/scripts/lib/ledger-match.js +39 -3
  26. package/plugins/harness-everything/hooks/scripts/lib/local-error-source.js +127 -0
  27. package/plugins/harness-everything/hooks/scripts/lib/local-errors.js +597 -0
  28. package/plugins/harness-everything/hooks/scripts/lib/observations.js +1 -1
  29. package/plugins/harness-everything/plugin.json +1 -1
  30. package/sbom.cdx.json +7 -7
  31. package/scripts/errors-local.js +357 -0
@@ -0,0 +1,234 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const assert = require('node:assert/strict');
5
+ const { execFileSync, spawnSync } = require('node:child_process');
6
+ const fs = require('node:fs');
7
+ const os = require('node:os');
8
+ const path = require('node:path');
9
+
10
+ const ROOT = path.resolve(__dirname, '..');
11
+ const CLI = path.join(ROOT, 'scripts', 'errors-local.js');
12
+ const localErrors = require(path.join(ROOT, 'hooks', 'scripts', 'lib', 'local-errors.js'));
13
+
14
+ let failures = 0;
15
+ const sandboxes = [];
16
+
17
+ function test(name, fn) {
18
+ try {
19
+ fn();
20
+ console.log(` PASS ${name}`);
21
+ } catch (error) {
22
+ failures += 1;
23
+ console.error(` FAIL ${name}\n ${error.stack.split('\n').slice(0, 5).join('\n ')}`);
24
+ }
25
+ }
26
+
27
+ function canonicalDir(dir) {
28
+ return fs.realpathSync.native ? fs.realpathSync.native(dir) : fs.realpathSync(dir);
29
+ }
30
+
31
+ function makeSandbox() {
32
+ const dir = canonicalDir(fs.mkdtempSync(path.join(os.tmpdir(), 'local-err-cli-edges-')));
33
+ sandboxes.push(dir);
34
+ const home = path.join(dir, 'home');
35
+ const store = path.join(dir, 'observations');
36
+ const stateHome = path.join(dir, 'state-home');
37
+ const repo = path.join(dir, 'repo');
38
+ for (const p of [home, store, stateHome, repo]) {
39
+ fs.mkdirSync(p, { recursive: true });
40
+ }
41
+ execFileSync('git', ['init', '-q', repo]);
42
+ const env = {
43
+ ...process.env,
44
+ HOME: home,
45
+ USERPROFILE: home,
46
+ HARNESS_OBSERVATIONS_DIR: store,
47
+ HARNESS_STATE_HOME: stateHome,
48
+ };
49
+ delete env.HARNESS_OBSERVATIONS;
50
+ delete env.HARNESS_SYSTEM_ONE_MODE;
51
+ delete env.HARNESS_WORKSPACE_ROOT;
52
+ delete env.CLAUDE_PROJECT_DIR;
53
+ delete env.CODEX_PROJECT_DIR;
54
+ return { dir, home, store, stateHome, repo, env };
55
+ }
56
+
57
+ function runCli(args, { cwd, env }) {
58
+ return spawnSync(process.execPath, [CLI, ...args], {
59
+ cwd,
60
+ env,
61
+ encoding: 'utf8',
62
+ stdio: ['ignore', 'pipe', 'pipe'],
63
+ });
64
+ }
65
+
66
+ console.log('mechanism-496-local-error-cli-edges:');
67
+
68
+ test('list and export reject --limit 0 with exit 2 while --limit >= 1 bounds output', () => {
69
+ const s = makeSandbox();
70
+ for (const suffix of ['one', 'two', 'three']) {
71
+ const addRes = runCli([
72
+ 'add',
73
+ '--executable', 'git',
74
+ '--subcommand', 'commit',
75
+ '--lesson', `Lesson ${suffix}`,
76
+ ], { cwd: s.repo, env: s.env });
77
+ assert.equal(addRes.status, 0, addRes.stderr);
78
+ }
79
+
80
+ for (const subcmd of ['list', 'export']) {
81
+ for (const badLimit of ['0', '00', '-1', 'abc']) {
82
+ const badRes = runCli([subcmd, '--limit', badLimit], { cwd: s.repo, env: s.env });
83
+ assert.equal(
84
+ badRes.status,
85
+ 2,
86
+ `expected ${subcmd} --limit ${badLimit} to exit 2, got ${badRes.status} (${badRes.stdout} / ${badRes.stderr})`
87
+ );
88
+ assert.match(badRes.stderr, /invalid --limit/);
89
+ }
90
+ }
91
+
92
+ // Positive controls: --limit 1 and --limit 2 return bounded records with exit 0.
93
+ const listOne = runCli(['list', '--limit', '1', '--json'], { cwd: s.repo, env: s.env });
94
+ assert.equal(listOne.status, 0, listOne.stderr);
95
+ const oneItems = JSON.parse(listOne.stdout);
96
+ assert.equal(oneItems.length, 1);
97
+ assert.equal(oneItems[0].lesson, 'Lesson three');
98
+
99
+ const exportTwo = runCli(['export', '--limit', '2'], { cwd: s.repo, env: s.env });
100
+ assert.equal(exportTwo.status, 0, exportTwo.stderr);
101
+ const exportedLines = exportTwo.stdout.trim().split('\n').map(line => JSON.parse(line));
102
+ assert.equal(exportedLines.length, 2);
103
+ assert.deepEqual(exportedLines.map(r => r.lesson), ['Lesson two', 'Lesson three']);
104
+ });
105
+
106
+ test('deriveSignature hashes redacted lesson so different HOMEs and secrets produce identical signature and provisionalId', () => {
107
+ const s = makeSandbox();
108
+ const homeAlice = path.join(s.dir, 'home-alice');
109
+ const homeBob = path.join(s.dir, 'home-bob');
110
+ const storeAlice = path.join(s.dir, 'obs-alice');
111
+ const storeBob = path.join(s.dir, 'obs-bob');
112
+ for (const p of [homeAlice, homeBob, storeAlice, storeBob]) {
113
+ fs.mkdirSync(p, { recursive: true });
114
+ }
115
+
116
+ const envAlice = { ...s.env, HOME: homeAlice, USERPROFILE: homeAlice, HARNESS_OBSERVATIONS_DIR: storeAlice };
117
+ const envBob = { ...s.env, HOME: homeBob, USERPROFILE: homeBob, HARNESS_OBSERVATIONS_DIR: storeBob };
118
+
119
+ const addAlice = runCli([
120
+ 'add',
121
+ '--executable', 'git',
122
+ '--subcommand', 'commit',
123
+ '--lesson', `Avoid ${homeAlice}/foo`,
124
+ '--json',
125
+ ], { cwd: s.repo, env: envAlice });
126
+ assert.equal(addAlice.status, 0, addAlice.stderr);
127
+ const recAlice = JSON.parse(addAlice.stdout).record;
128
+
129
+ const addBob = runCli([
130
+ 'add',
131
+ '--executable', 'git',
132
+ '--subcommand', 'commit',
133
+ '--lesson', `Avoid ${homeBob}/foo`,
134
+ '--json',
135
+ ], { cwd: s.repo, env: envBob });
136
+ assert.equal(addBob.status, 0, addBob.stderr);
137
+ const recBob = JSON.parse(addBob.stdout).record;
138
+
139
+ assert.equal(recAlice.lesson, 'Avoid <home>/foo');
140
+ assert.equal(recBob.lesson, 'Avoid <home>/foo');
141
+ assert.equal(recAlice.signature, recBob.signature, 'identical redacted lessons must derive identical signatures across HOMEs');
142
+ assert.equal(recAlice.provisionalId, recBob.provisionalId, 'identical redacted lessons must derive identical provisionalIds');
143
+
144
+ // Token and email redaction also collapse before signature derivation.
145
+ const addSecretA = runCli([
146
+ 'add',
147
+ '--executable', 'git',
148
+ '--subcommand', 'commit',
149
+ '--lesson', 'Never commit alice@example.com or ghp_1234567890abcdefghijklmnopqrstuv',
150
+ '--json',
151
+ ], { cwd: s.repo, env: envAlice });
152
+ assert.equal(addSecretA.status, 0, addSecretA.stderr);
153
+
154
+ const addSecretB = runCli([
155
+ 'add',
156
+ '--executable', 'git',
157
+ '--subcommand', 'commit',
158
+ '--lesson', 'Never commit bob@example.org or ghp_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
159
+ '--json',
160
+ ], { cwd: s.repo, env: envBob });
161
+ assert.equal(addSecretB.status, 0, addSecretB.stderr);
162
+
163
+ assert.equal(
164
+ JSON.parse(addSecretA.stdout).record.signature,
165
+ JSON.parse(addSecretB.stdout).record.signature,
166
+ 'emails and tokens must redact before signature derivation'
167
+ );
168
+
169
+ // Positive control: distinct redacted lessons still derive distinct signatures.
170
+ const addDifferent = runCli([
171
+ 'add',
172
+ '--executable', 'git',
173
+ '--subcommand', 'commit',
174
+ '--lesson', `Avoid ${homeAlice}/bar`,
175
+ '--json',
176
+ ], { cwd: s.repo, env: envAlice });
177
+ assert.equal(addDifferent.status, 0, addDifferent.stderr);
178
+ const recDifferent = JSON.parse(addDifferent.stdout).record;
179
+ assert.notEqual(recDifferent.signature, recAlice.signature);
180
+ assert.notEqual(recDifferent.provisionalId, recAlice.provisionalId);
181
+ });
182
+
183
+ test('add exits 1 on store I/O error (EISDIR on rename) and exits 2 on store validation errors', () => {
184
+ const s = makeSandbox();
185
+ const storeFile = localErrors.getStorePath({ env: s.env }).file;
186
+ // Create a directory at errors-index.json so fs.renameSync throws EISDIR cross-platform.
187
+ fs.mkdirSync(storeFile, { recursive: true });
188
+
189
+ const ioErrRes = runCli([
190
+ 'add',
191
+ '--executable', 'git',
192
+ '--subcommand', 'commit',
193
+ '--lesson', 'Valid lesson hitting store I/O failure',
194
+ ], { cwd: s.repo, env: s.env });
195
+ assert.equal(
196
+ ioErrRes.status,
197
+ 1,
198
+ `expected EISDIR store I/O error to exit 1, got ${ioErrRes.status} (${ioErrRes.stdout} / ${ioErrRes.stderr})`
199
+ );
200
+ assert.match(ioErrRes.stderr, /^error:/);
201
+ assert.doesNotMatch(ioErrRes.stderr, /^usage error:/);
202
+
203
+ // Validation errors from the store still exit 2.
204
+ const validationCases = [
205
+ ['add', '--executable', 'git', '--subcommand', 'commit', '--lesson', 'x', '--issue', 'https://github.com/org/repo/issues/1#ghp_1234567890abcdefghijklmnopqrstuv'],
206
+ ['add', '--executable', 'git', '--subcommand', 'commit', '--lesson', 'x', '--promotion-id', 'not-an-e-id'],
207
+ ['add', '--executable', 'git', '--subcommand', 'commit', '--lesson', 'x', '--destination', 'invalid-dest'],
208
+ ];
209
+ for (const args of validationCases) {
210
+ const valRes = runCli(args, { cwd: s.repo, env: s.env });
211
+ assert.equal(valRes.status, 2, `expected validation error exit 2 for ${JSON.stringify(args)}, got ${valRes.status}`);
212
+ assert.match(valRes.stderr, /^usage error:/);
213
+ }
214
+
215
+ // Positive control: clean store succeeds with exit 0.
216
+ fs.rmSync(storeFile, { recursive: true, force: true });
217
+ const okRes = runCli([
218
+ 'add',
219
+ '--executable', 'git',
220
+ '--subcommand', 'commit',
221
+ '--lesson', 'Valid lesson on clean store',
222
+ ], { cwd: s.repo, env: s.env });
223
+ assert.equal(okRes.status, 0, okRes.stderr);
224
+ });
225
+
226
+ for (const dir of sandboxes) {
227
+ try { fs.rmSync(dir, { recursive: true, force: true }); } catch (_) {}
228
+ }
229
+
230
+ if (failures > 0) {
231
+ console.error(`\n${failures} test(s) failed`);
232
+ process.exit(1);
233
+ }
234
+ console.log('\nall tests passed');