oh-my-codex 0.22.1 → 0.22.2
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/Cargo.lock +6 -6
- package/Cargo.toml +1 -1
- package/dist/team/__tests__/p1-safety.test.d.ts +2 -0
- package/dist/team/__tests__/p1-safety.test.d.ts.map +1 -0
- package/dist/team/__tests__/p1-safety.test.js +553 -0
- package/dist/team/__tests__/p1-safety.test.js.map +1 -0
- package/dist/team/__tests__/state.test.js +6 -3
- package/dist/team/__tests__/state.test.js.map +1 -1
- package/dist/team/completion-evidence.d.ts +1 -0
- package/dist/team/completion-evidence.d.ts.map +1 -1
- package/dist/team/completion-evidence.js +21 -7
- package/dist/team/completion-evidence.js.map +1 -1
- package/dist/team/runtime.d.ts.map +1 -1
- package/dist/team/runtime.js +130 -54
- package/dist/team/runtime.js.map +1 -1
- package/dist/team/scaling.d.ts.map +1 -1
- package/dist/team/scaling.js +5 -4
- package/dist/team/scaling.js.map +1 -1
- package/dist/team/state/tasks.d.ts.map +1 -1
- package/dist/team/state/tasks.js +20 -17
- package/dist/team/state/tasks.js.map +1 -1
- package/dist/team/state.d.ts.map +1 -1
- package/dist/team/state.js +16 -11
- package/dist/team/state.js.map +1 -1
- package/dist/team/worktree.d.ts +1 -0
- package/dist/team/worktree.d.ts.map +1 -1
- package/dist/team/worktree.js +64 -11
- package/dist/team/worktree.js.map +1 -1
- package/package.json +1 -1
- package/plugins/oh-my-codex/.codex-plugin/plugin.json +1 -1
package/Cargo.lock
CHANGED
|
@@ -32,7 +32,7 @@ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
|
|
32
32
|
|
|
33
33
|
[[package]]
|
|
34
34
|
name = "omx-api"
|
|
35
|
-
version = "0.22.
|
|
35
|
+
version = "0.22.2"
|
|
36
36
|
dependencies = [
|
|
37
37
|
"serde",
|
|
38
38
|
"serde_json",
|
|
@@ -40,14 +40,14 @@ dependencies = [
|
|
|
40
40
|
|
|
41
41
|
[[package]]
|
|
42
42
|
name = "omx-explore-harness"
|
|
43
|
-
version = "0.22.
|
|
43
|
+
version = "0.22.2"
|
|
44
44
|
dependencies = [
|
|
45
45
|
"libc",
|
|
46
46
|
]
|
|
47
47
|
|
|
48
48
|
[[package]]
|
|
49
49
|
name = "omx-mux"
|
|
50
|
-
version = "0.22.
|
|
50
|
+
version = "0.22.2"
|
|
51
51
|
dependencies = [
|
|
52
52
|
"serde",
|
|
53
53
|
"serde_json",
|
|
@@ -55,7 +55,7 @@ dependencies = [
|
|
|
55
55
|
|
|
56
56
|
[[package]]
|
|
57
57
|
name = "omx-runtime"
|
|
58
|
-
version = "0.22.
|
|
58
|
+
version = "0.22.2"
|
|
59
59
|
dependencies = [
|
|
60
60
|
"fs2",
|
|
61
61
|
"libc",
|
|
@@ -67,7 +67,7 @@ dependencies = [
|
|
|
67
67
|
|
|
68
68
|
[[package]]
|
|
69
69
|
name = "omx-runtime-core"
|
|
70
|
-
version = "0.22.
|
|
70
|
+
version = "0.22.2"
|
|
71
71
|
dependencies = [
|
|
72
72
|
"fs2",
|
|
73
73
|
"serde",
|
|
@@ -76,7 +76,7 @@ dependencies = [
|
|
|
76
76
|
|
|
77
77
|
[[package]]
|
|
78
78
|
name = "omx-sparkshell"
|
|
79
|
-
version = "0.22.
|
|
79
|
+
version = "0.22.2"
|
|
80
80
|
dependencies = [
|
|
81
81
|
"omx-mux",
|
|
82
82
|
]
|
package/Cargo.toml
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"p1-safety.test.d.ts","sourceRoot":"","sources":["../../../src/team/__tests__/p1-safety.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import { execFileSync, spawnSync, spawn } from 'node:child_process';
|
|
4
|
+
import fsPromises, { mkdtemp, mkdir, writeFile, readFile, rm, readdir, symlink, rename } from 'node:fs/promises';
|
|
5
|
+
import { syncBuiltinESMExports } from 'node:module';
|
|
6
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
7
|
+
import { join, resolve } from 'node:path';
|
|
8
|
+
import { tmpdir } from 'node:os';
|
|
9
|
+
import { createHash } from 'node:crypto';
|
|
10
|
+
import * as S from '../state.js';
|
|
11
|
+
import { monitorTeam, shutdownTeam } from '../runtime.js';
|
|
12
|
+
import { scaleDown } from '../scaling.js';
|
|
13
|
+
import { archiveIgnoredCompletionEvidence, rollbackProvisionedWorktrees } from '../worktree.js';
|
|
14
|
+
import { readTeamEvents } from '../state/events.js';
|
|
15
|
+
process.env.OMX_RUNTIME_BRIDGE = '0';
|
|
16
|
+
process.env.OMX_TEAM_WORKER_LAUNCH_MODE = 'prompt';
|
|
17
|
+
delete process.env.OMX_TEAM_STATE_ROOT;
|
|
18
|
+
delete process.env.OMX_TEAM_WORKER;
|
|
19
|
+
const git = (cwd, ...args) => execFileSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
|
|
20
|
+
async function fixture(count = 1) {
|
|
21
|
+
const repo = await mkdtemp(join(realpathSync(tmpdir()), 'omx-team-audit-'));
|
|
22
|
+
git(repo, 'init');
|
|
23
|
+
git(repo, 'config', 'user.name', 'Audit');
|
|
24
|
+
git(repo, 'config', 'user.email', 'audit@example.invalid');
|
|
25
|
+
git(repo, 'config', 'commit.gpgsign', 'false');
|
|
26
|
+
await writeFile(join(repo, '.git/info/exclude'), '.omx/\n');
|
|
27
|
+
await writeFile(join(repo, 'README.md'), 'base\n');
|
|
28
|
+
git(repo, 'add', 'README.md');
|
|
29
|
+
git(repo, 'commit', '-m', 'base');
|
|
30
|
+
const base = git(repo, 'rev-parse', 'HEAD');
|
|
31
|
+
await S.initTeamState('audit', 'Audit fixture', 'executor', count, repo);
|
|
32
|
+
const cfg = await S.readTeamConfig('audit', repo);
|
|
33
|
+
assert.ok(cfg);
|
|
34
|
+
cfg.leader_pane_id = '';
|
|
35
|
+
cfg.worker_launch_mode = 'prompt';
|
|
36
|
+
const wt = join(repo, '.omx/team/audit/worktrees/worker-1');
|
|
37
|
+
git(repo, 'worktree', 'add', '-b', 'audit-worker', wt, base);
|
|
38
|
+
Object.assign(cfg.workers[0], { worktree_repo_root: repo, worktree_path: wt,
|
|
39
|
+
worktree_branch: 'audit-worker', worktree_detached: false, worktree_created: true });
|
|
40
|
+
await S.saveTeamConfig(cfg, repo);
|
|
41
|
+
return { repo, wt, base };
|
|
42
|
+
}
|
|
43
|
+
async function complete(repo, wt, worker = 'worker-1', file = 'worker.js') {
|
|
44
|
+
execFileSync(process.execPath, ['--check', join(wt, file)], { stdio: 'pipe' });
|
|
45
|
+
const command = `node --check ${file}`;
|
|
46
|
+
const task = await S.createTask('audit', { subject: 'Code', description: 'Verified output', status: 'pending', requires_code_change: true }, repo);
|
|
47
|
+
const claim = await S.claimTask('audit', task.id, worker, null, repo);
|
|
48
|
+
assert.ok(claim.ok, JSON.stringify(claim));
|
|
49
|
+
await mkdir(join(wt, '.omx/evidence'), { recursive: true });
|
|
50
|
+
await writeFile(join(wt, '.omx/evidence/handoff.json'), JSON.stringify({ teamName: 'audit', taskId: task.id,
|
|
51
|
+
claimTokenSha256: createHash('sha256').update(claim.claimToken).digest('hex'),
|
|
52
|
+
verifiedHead: git(wt, 'rev-parse', 'HEAD'), summary: 'Verified code',
|
|
53
|
+
verification: [{ command, result: 'passed', output: 'Syntax valid' }], unverified: [] }));
|
|
54
|
+
const result = await S.transitionTaskStatus('audit', task.id, 'in_progress', 'completed', claim.claimToken, repo, { result: `Verification: PASS ${command}\nEVIDENCE_RECORDED: .omx/evidence/handoff.json` }, wt);
|
|
55
|
+
assert.equal(result.ok, true, JSON.stringify(result));
|
|
56
|
+
await S.writeWorkerStatus('audit', worker, { state: 'done', updated_at: new Date().toISOString() }, repo);
|
|
57
|
+
return task;
|
|
58
|
+
}
|
|
59
|
+
async function addWorkerCommit(wt) {
|
|
60
|
+
await writeFile(join(wt, 'worker.js'), 'export const answer = 42;\n');
|
|
61
|
+
git(wt, 'add', 'worker.js');
|
|
62
|
+
git(wt, 'commit', '-m', 'worker output');
|
|
63
|
+
}
|
|
64
|
+
function beginCleanManualMerge(wt) {
|
|
65
|
+
git(wt, 'checkout', '-b', 'manual-pending');
|
|
66
|
+
git(wt, 'commit', '--allow-empty', '-m', 'manual empty merge source');
|
|
67
|
+
const source = git(wt, 'rev-parse', 'HEAD');
|
|
68
|
+
git(wt, 'checkout', '-');
|
|
69
|
+
git(wt, 'merge', '--no-ff', '--no-commit', source);
|
|
70
|
+
assert.equal(git(wt, 'status', '--porcelain', '--untracked-files=all'), '');
|
|
71
|
+
return resolve(wt, git(wt, 'rev-parse', '--git-path', 'MERGE_HEAD'));
|
|
72
|
+
}
|
|
73
|
+
async function twoVerifiedWorkers() {
|
|
74
|
+
const result = await fixture(2);
|
|
75
|
+
const { repo, wt, base } = result;
|
|
76
|
+
const second = join(repo, '.omx/team/audit/worktrees/worker-2');
|
|
77
|
+
git(repo, 'worktree', 'add', '-b', 'second-worker', second, base);
|
|
78
|
+
const cfg = await S.readTeamConfig('audit', repo);
|
|
79
|
+
assert.ok(cfg);
|
|
80
|
+
Object.assign(cfg.workers[1], { worktree_repo_root: repo, worktree_path: second, worktree_branch: 'second-worker', worktree_created: true, worktree_detached: false });
|
|
81
|
+
await S.saveTeamConfig(cfg, repo);
|
|
82
|
+
await addWorkerCommit(wt);
|
|
83
|
+
await complete(repo, wt);
|
|
84
|
+
await writeFile(join(second, 'second.js'), 'export const second = 2;\n');
|
|
85
|
+
git(second, 'add', 'second.js');
|
|
86
|
+
git(second, 'commit', '-m', 'second worker output');
|
|
87
|
+
await complete(repo, second, 'worker-2', 'second.js');
|
|
88
|
+
return { ...result, second };
|
|
89
|
+
}
|
|
90
|
+
test('monitor preserves the leader manual cherry-pick and staged resolution', async () => {
|
|
91
|
+
const { repo, wt, base } = await fixture();
|
|
92
|
+
try {
|
|
93
|
+
git(repo, 'checkout', '-b', 'manual-source', base);
|
|
94
|
+
await writeFile(join(repo, 'README.md'), 'manual branch\n');
|
|
95
|
+
git(repo, 'add', 'README.md');
|
|
96
|
+
git(repo, 'commit', '-m', 'manual source');
|
|
97
|
+
const manual = git(repo, 'rev-parse', 'HEAD');
|
|
98
|
+
git(repo, 'checkout', '-');
|
|
99
|
+
await writeFile(join(repo, 'README.md'), 'leader branch\n');
|
|
100
|
+
git(repo, 'add', 'README.md');
|
|
101
|
+
git(repo, 'commit', '-m', 'leader divergent');
|
|
102
|
+
await addWorkerCommit(wt);
|
|
103
|
+
await complete(repo, wt);
|
|
104
|
+
assert.notEqual(spawnSync('git', ['cherry-pick', manual], { cwd: repo }).status, 0);
|
|
105
|
+
await writeFile(join(repo, 'README.md'), 'valuable manual resolution\n');
|
|
106
|
+
git(repo, 'add', 'README.md');
|
|
107
|
+
assert.equal(existsSync(join(repo, '.git/CHERRY_PICK_HEAD')), true);
|
|
108
|
+
const staged = git(repo, 'diff', '--cached');
|
|
109
|
+
await assert.rejects(monitorTeam('audit', repo), /git_operation_in_progress/);
|
|
110
|
+
assert.equal(existsSync(join(repo, '.git/CHERRY_PICK_HEAD')), true);
|
|
111
|
+
assert.equal(await readFile(join(repo, 'README.md'), 'utf8'), 'valuable manual resolution\n');
|
|
112
|
+
assert.equal(git(repo, 'diff', '--cached'), staged);
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
await rm(repo, { recursive: true, force: true });
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
for (const action of ['monitor', 'shutdown']) {
|
|
119
|
+
test(`${action} preserves a manual leader merge and staged changes`, async () => {
|
|
120
|
+
const { repo, wt, base } = await fixture();
|
|
121
|
+
try {
|
|
122
|
+
git(repo, 'checkout', '-b', 'manual-source', base);
|
|
123
|
+
await writeFile(join(repo, 'README.md'), 'manual merge\n');
|
|
124
|
+
git(repo, 'add', 'README.md');
|
|
125
|
+
git(repo, 'commit', '-m', 'manual source');
|
|
126
|
+
const manual = git(repo, 'rev-parse', 'HEAD');
|
|
127
|
+
git(repo, 'checkout', '-');
|
|
128
|
+
await addWorkerCommit(wt);
|
|
129
|
+
await complete(repo, wt);
|
|
130
|
+
git(repo, 'merge', '--no-commit', '--no-ff', manual);
|
|
131
|
+
await writeFile(join(repo, 'README.md'), 'valuable staged merge edit\n');
|
|
132
|
+
git(repo, 'add', 'README.md');
|
|
133
|
+
const staged = git(repo, 'diff', '--cached');
|
|
134
|
+
await assert.rejects(action === 'monitor' ? monitorTeam('audit', repo) : shutdownTeam('audit', repo), /git_operation_in_progress/);
|
|
135
|
+
assert.equal(existsSync(join(repo, '.git/MERGE_HEAD')), true);
|
|
136
|
+
assert.equal(git(repo, 'diff', '--cached'), staged);
|
|
137
|
+
assert.equal(await readFile(join(repo, 'README.md'), 'utf8'), 'valuable staged merge edit\n');
|
|
138
|
+
assert.equal(existsSync(join(repo, '.omx/state/team/audit')), true);
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
await rm(repo, { recursive: true, force: true });
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
for (const corrupt of ['json', 'shape', 'id', 'directory']) {
|
|
146
|
+
test(`task ${corrupt} corruption blocks monitoring and non-force shutdown without deleting state`, async () => {
|
|
147
|
+
const repo = await mkdtemp(join(realpathSync(tmpdir()), 'omx-team-corrupt-'));
|
|
148
|
+
try {
|
|
149
|
+
await S.initTeamState('audit', 'Audit corruption', 'executor', 1, repo);
|
|
150
|
+
const phase = await S.readTeamPhase('audit', repo);
|
|
151
|
+
const task = await S.createTask('audit', { subject: 'Unfinished', description: 'Must not disappear', status: 'pending' }, repo);
|
|
152
|
+
const path = join(repo, '.omx/state/team/audit/tasks', `task-${task.id}.json`);
|
|
153
|
+
const bytes = corrupt === 'json' ? '{"status":"pending",' : JSON.stringify(corrupt === 'id' ? { ...task, id: '999' } : { nope: true });
|
|
154
|
+
if (corrupt === 'directory') {
|
|
155
|
+
await rm(path);
|
|
156
|
+
await mkdir(path);
|
|
157
|
+
}
|
|
158
|
+
else
|
|
159
|
+
await writeFile(path, bytes);
|
|
160
|
+
for (const read of [S.listTasks, S.listTasksSnapshot, monitorTeam, shutdownTeam]) {
|
|
161
|
+
await assert.rejects(read('audit', repo), /team_task_read_failed/);
|
|
162
|
+
assert.equal(existsSync(path), true);
|
|
163
|
+
if (corrupt !== 'directory')
|
|
164
|
+
assert.equal(await readFile(path, 'utf8'), bytes);
|
|
165
|
+
}
|
|
166
|
+
assert.deepEqual(await S.readTeamPhase('audit', repo), phase);
|
|
167
|
+
}
|
|
168
|
+
finally {
|
|
169
|
+
await rm(repo, { recursive: true, force: true });
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
for (const action of ['scale-down', 'shutdown']) {
|
|
174
|
+
test(`${action} accepts ignored completion evidence after verified integration`, async () => {
|
|
175
|
+
const { repo, wt } = await fixture(2);
|
|
176
|
+
try {
|
|
177
|
+
git(wt, 'checkout', '--detach');
|
|
178
|
+
const cfg = await S.readTeamConfig('audit', repo);
|
|
179
|
+
assert.ok(cfg);
|
|
180
|
+
cfg.workers[0].worktree_detached = true;
|
|
181
|
+
cfg.workers[0].worktree_branch = undefined;
|
|
182
|
+
await S.saveTeamConfig(cfg, repo);
|
|
183
|
+
await addWorkerCommit(wt);
|
|
184
|
+
await complete(repo, wt);
|
|
185
|
+
await monitorTeam('audit', repo);
|
|
186
|
+
git(repo, 'merge-base', '--is-ancestor', git(wt, 'rev-parse', 'HEAD'), 'HEAD');
|
|
187
|
+
assert.equal(git(wt, 'status', '--porcelain', '--untracked-files=all'), '');
|
|
188
|
+
const ignored = git(wt, 'status', '--porcelain', '--ignored');
|
|
189
|
+
assert.match(ignored, /\.omx\//);
|
|
190
|
+
const report = await readFile(join(wt, '.omx/evidence/handoff.json'), 'utf8');
|
|
191
|
+
if (action === 'scale-down') {
|
|
192
|
+
const result = await scaleDown('audit', repo, { workerNames: ['worker-1'], drainTimeoutMs: 0 }, { ...process.env, OMX_TEAM_SCALING_ENABLED: '1' });
|
|
193
|
+
assert.ok(result.ok, JSON.stringify(result));
|
|
194
|
+
assert.equal((await S.readTeamConfig('audit', repo))?.workers.length, 1);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
await shutdownTeam('audit', repo);
|
|
198
|
+
assert.equal(existsSync(join(repo, '.omx/state/team/audit')), false);
|
|
199
|
+
}
|
|
200
|
+
assert.equal(existsSync(wt), false);
|
|
201
|
+
const archive = join(repo, '.git/omx-completion-evidence');
|
|
202
|
+
const records = await readdir(archive);
|
|
203
|
+
assert.ok((await Promise.all(records.map(file => readFile(join(archive, file), 'utf8')))).includes(report));
|
|
204
|
+
}
|
|
205
|
+
finally {
|
|
206
|
+
await rm(repo, { recursive: true, force: true });
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
for (const action of ['scale-down', 'shutdown']) {
|
|
211
|
+
for (const path of ['.omx/cache.bin', '.omx/evidence/personal.json']) {
|
|
212
|
+
test(`${action} retains unrecognized ignored files at ${path}`, async () => {
|
|
213
|
+
const { repo, wt } = await fixture(2);
|
|
214
|
+
try {
|
|
215
|
+
git(wt, 'checkout', '--detach');
|
|
216
|
+
const cfg = await S.readTeamConfig('audit', repo);
|
|
217
|
+
assert.ok(cfg);
|
|
218
|
+
cfg.workers[0].worktree_detached = true;
|
|
219
|
+
cfg.workers[0].worktree_branch = undefined;
|
|
220
|
+
await S.saveTeamConfig(cfg, repo);
|
|
221
|
+
await addWorkerCommit(wt);
|
|
222
|
+
await complete(repo, wt);
|
|
223
|
+
await monitorTeam('audit', repo);
|
|
224
|
+
await writeFile(join(wt, path), 'personal data');
|
|
225
|
+
if (action === 'scale-down') {
|
|
226
|
+
const result = await scaleDown('audit', repo, { workerNames: ['worker-1'], drainTimeoutMs: 0 }, { ...process.env, OMX_TEAM_SCALING_ENABLED: '1' });
|
|
227
|
+
assert.equal(result.ok, false);
|
|
228
|
+
}
|
|
229
|
+
else
|
|
230
|
+
await assert.rejects(shutdownTeam('audit', repo), /shutdown_worktree_preservation_failed/);
|
|
231
|
+
assert.equal(await readFile(join(wt, path), 'utf8'), 'personal data');
|
|
232
|
+
assert.equal(existsSync(join(repo, '.omx/state/team/audit')), true);
|
|
233
|
+
}
|
|
234
|
+
finally {
|
|
235
|
+
await rm(repo, { recursive: true, force: true });
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
test('evidence archiving preserves tracked, unignored and symlinked reports', { skip: process.platform === 'win32' }, async () => {
|
|
241
|
+
const { repo, wt } = await fixture();
|
|
242
|
+
const outside = await mkdtemp(join(realpathSync(tmpdir()), 'omx-evidence-outside-'));
|
|
243
|
+
try {
|
|
244
|
+
await addWorkerCommit(wt);
|
|
245
|
+
await complete(repo, wt);
|
|
246
|
+
const report = await readFile(join(wt, '.omx/evidence/handoff.json'), 'utf8');
|
|
247
|
+
await writeFile(join(wt, '.omx/evidence/tracked.json'), report);
|
|
248
|
+
git(wt, 'add', '-f', '.omx/evidence/tracked.json');
|
|
249
|
+
await writeFile(join(outside, 'report.json'), report);
|
|
250
|
+
await symlink(join(outside, 'report.json'), join(wt, '.omx/evidence/link.json'));
|
|
251
|
+
await symlink(outside, join(wt, '.omx/evidence/linked-dir'));
|
|
252
|
+
await writeFile(join(wt, '.omx/evidence/unignored.json'), report);
|
|
253
|
+
await writeFile(join(repo, '.git/info/exclude'), '.omx/*\n!.omx/evidence/\n.omx/evidence/*\n!.omx/evidence/unignored.json\n');
|
|
254
|
+
await archiveIgnoredCompletionEvidence(wt);
|
|
255
|
+
assert.equal(existsSync(join(wt, '.omx/evidence/handoff.json')), false);
|
|
256
|
+
for (const path of ['tracked.json', 'link.json', 'linked-dir/report.json', 'unignored.json']) {
|
|
257
|
+
assert.equal(await readFile(join(wt, '.omx/evidence', path), 'utf8'), report);
|
|
258
|
+
}
|
|
259
|
+
assert.equal(await readFile(join(outside, 'report.json'), 'utf8'), report);
|
|
260
|
+
assert.match(git(wt, 'diff', '--cached', '--name-only'), /tracked\.json/);
|
|
261
|
+
}
|
|
262
|
+
finally {
|
|
263
|
+
await rm(repo, { recursive: true, force: true });
|
|
264
|
+
await rm(outside, { recursive: true, force: true });
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
for (const mode of ['missing', 'symlink']) {
|
|
268
|
+
test(`a ${mode} task directory blocks false completion and cleanup`, async () => {
|
|
269
|
+
const repo = await mkdtemp(join(realpathSync(tmpdir()), 'omx-task-dir-regression-'));
|
|
270
|
+
try {
|
|
271
|
+
await S.initTeamState('audit', 'Task root corruption', 'executor', 1, repo);
|
|
272
|
+
const task = await S.createTask('audit', { subject: 'Pending', description: 'Not finished', status: 'pending' }, repo);
|
|
273
|
+
const teamRoot = join(repo, '.omx/state/team/audit');
|
|
274
|
+
await rename(join(teamRoot, 'tasks'), join(teamRoot, 'tasks.saved'));
|
|
275
|
+
if (mode === 'symlink')
|
|
276
|
+
await symlink(join(teamRoot, 'tasks.saved'), join(teamRoot, 'tasks'), process.platform === 'win32' ? 'junction' : 'dir');
|
|
277
|
+
const saved = join(teamRoot, 'tasks.saved', `task-${task.id}.json`);
|
|
278
|
+
for (const read of [S.listTasks, S.listTasksSnapshot, monitorTeam, shutdownTeam]) {
|
|
279
|
+
await assert.rejects(read('audit', repo), /team_task_read_failed/);
|
|
280
|
+
assert.equal(existsSync(saved), true);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
finally {
|
|
284
|
+
await rm(repo, { recursive: true, force: true });
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
test('task enumeration distinguishes an absent Team from an empty Team', async () => {
|
|
289
|
+
const repo = await mkdtemp(join(realpathSync(tmpdir()), 'omx-empty-team-'));
|
|
290
|
+
try {
|
|
291
|
+
assert.deepEqual(await S.listTasks('missing', repo), []);
|
|
292
|
+
await S.initTeamState('audit', 'Empty team', 'executor', 1, repo);
|
|
293
|
+
assert.deepEqual(await S.listTasks('audit', repo), []);
|
|
294
|
+
}
|
|
295
|
+
finally {
|
|
296
|
+
await rm(repo, { recursive: true, force: true });
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
test('a worker manual Git operation blocks only that worker and permits a safe retry', async () => {
|
|
300
|
+
const { repo, second } = await twoVerifiedWorkers();
|
|
301
|
+
try {
|
|
302
|
+
const marker = beginCleanManualMerge(second);
|
|
303
|
+
await monitorTeam('audit', repo);
|
|
304
|
+
assert.equal(existsSync(marker), true);
|
|
305
|
+
assert.equal(existsSync(join(repo, 'worker.js')), true);
|
|
306
|
+
assert.equal(existsSync(join(repo, 'second.js')), false);
|
|
307
|
+
const snapshot = await S.readMonitorSnapshot('audit', repo);
|
|
308
|
+
assert.ok(snapshot?.integrationByWorker?.['worker-1']?.delivery_leader_commit);
|
|
309
|
+
assert.equal(snapshot?.integrationByWorker?.['worker-2']?.status, 'rebase_conflict');
|
|
310
|
+
git(second, 'merge', '--abort');
|
|
311
|
+
await monitorTeam('audit', repo);
|
|
312
|
+
assert.equal(await readFile(join(repo, 'second.js'), 'utf8'), 'export const second = 2;\n');
|
|
313
|
+
assert.notEqual((await S.readMonitorSnapshot('audit', repo))?.integrationByWorker?.['worker-2']?.status, 'cherry_pick_conflict');
|
|
314
|
+
}
|
|
315
|
+
finally {
|
|
316
|
+
await rm(repo, { recursive: true, force: true });
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
for (const target of ['worker', 'leader', 'phase-write']) {
|
|
320
|
+
test(`a late ${target} Git operation preserves prior integration receipts`, async () => {
|
|
321
|
+
const { repo, second } = await twoVerifiedWorkers();
|
|
322
|
+
const original = fsPromises.appendFile;
|
|
323
|
+
const originalOpen = fsPromises.open;
|
|
324
|
+
let marker = '';
|
|
325
|
+
try {
|
|
326
|
+
fsPromises.appendFile = async (...args) => {
|
|
327
|
+
await original(...args);
|
|
328
|
+
if (marker || !String(args[0]).endsWith(join('events', 'events.ndjson')))
|
|
329
|
+
return;
|
|
330
|
+
const event = JSON.parse(String(args[1]));
|
|
331
|
+
if (target !== 'leader' && event.type === 'worker_cherry_pick_applied' && event.worker === 'worker-2')
|
|
332
|
+
marker = beginCleanManualMerge(second);
|
|
333
|
+
if (target === 'leader' && event.type === 'worker_merge_applied' && event.worker === 'worker-1')
|
|
334
|
+
marker = beginCleanManualMerge(repo);
|
|
335
|
+
};
|
|
336
|
+
S.setWriteAtomicOpenForTests(async (...args) => {
|
|
337
|
+
if (target === 'phase-write' && marker && String(args[0]).includes('phase.json'))
|
|
338
|
+
throw new Error('phase_write_io');
|
|
339
|
+
return originalOpen(...args);
|
|
340
|
+
});
|
|
341
|
+
syncBuiltinESMExports();
|
|
342
|
+
if (target === 'leader')
|
|
343
|
+
await assert.rejects(monitorTeam('audit', repo), /git_operation_in_progress/);
|
|
344
|
+
else if (target === 'phase-write')
|
|
345
|
+
await assert.rejects(monitorTeam('audit', repo), /phase_write_io/);
|
|
346
|
+
else
|
|
347
|
+
await monitorTeam('audit', repo);
|
|
348
|
+
fsPromises.appendFile = original;
|
|
349
|
+
syncBuiltinESMExports();
|
|
350
|
+
S.resetWriteAtomicOpenForTests();
|
|
351
|
+
assert.ok(marker && existsSync(marker));
|
|
352
|
+
const snapshot = await S.readMonitorSnapshot('audit', repo);
|
|
353
|
+
const worker = target === 'leader' ? 'worker-1' : 'worker-2';
|
|
354
|
+
assert.ok(snapshot?.integrationByWorker?.[worker]?.delivery_leader_commit);
|
|
355
|
+
git(target === 'leader' ? repo : second, 'merge', '--abort');
|
|
356
|
+
await monitorTeam('audit', repo);
|
|
357
|
+
const events = await readTeamEvents('audit', repo);
|
|
358
|
+
assert.equal(events.filter(e => e.worker === 'worker-1' && e.type === 'worker_merge_applied').length, 1);
|
|
359
|
+
assert.equal(events.filter(e => e.worker === 'worker-2' && e.type === 'worker_cherry_pick_applied').length, 1);
|
|
360
|
+
assert.notEqual((await S.readMonitorSnapshot('audit', repo))?.integrationByWorker?.['worker-2']?.status, 'cherry_pick_conflict');
|
|
361
|
+
}
|
|
362
|
+
finally {
|
|
363
|
+
fsPromises.appendFile = original;
|
|
364
|
+
syncBuiltinESMExports();
|
|
365
|
+
S.resetWriteAtomicOpenForTests();
|
|
366
|
+
await rm(repo, { recursive: true, force: true });
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
for (const target of ['worker', 'leader']) {
|
|
371
|
+
test(`forced shutdown stops its worker and retains a ${target} manual Git operation`, async () => {
|
|
372
|
+
const { repo, wt } = await fixture();
|
|
373
|
+
const child = spawn(process.execPath, ['-e', 'setInterval(() => {}, 1000)'], { stdio: 'ignore' });
|
|
374
|
+
try {
|
|
375
|
+
await addWorkerCommit(wt);
|
|
376
|
+
await complete(repo, wt);
|
|
377
|
+
const cfg = await S.readTeamConfig('audit', repo);
|
|
378
|
+
assert.ok(cfg);
|
|
379
|
+
cfg.workers[0].pid = child.pid;
|
|
380
|
+
await S.saveTeamConfig(cfg, repo);
|
|
381
|
+
const marker = beginCleanManualMerge(target === 'worker' ? wt : repo);
|
|
382
|
+
await assert.rejects(shutdownTeam('audit', repo, { force: true }), /git_operation_in_progress/);
|
|
383
|
+
assert.throws(() => process.kill(child.pid, 0), /ESRCH/);
|
|
384
|
+
assert.equal(existsSync(marker), true);
|
|
385
|
+
assert.equal(existsSync(join(wt, 'worker.js')), true);
|
|
386
|
+
const after = await S.readTeamConfig('audit', repo);
|
|
387
|
+
assert.ok(after);
|
|
388
|
+
assert.equal(after.workers[0].pid, undefined);
|
|
389
|
+
}
|
|
390
|
+
finally {
|
|
391
|
+
if (child.exitCode === null && child.signalCode === null) {
|
|
392
|
+
const exited = new Promise(resolve => child.once('exit', resolve));
|
|
393
|
+
child.kill('SIGKILL');
|
|
394
|
+
await exited;
|
|
395
|
+
}
|
|
396
|
+
await rm(repo, { recursive: true, force: true });
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
for (const boundary of ['task-read', 'integration']) {
|
|
401
|
+
test(`a completion at ${boundary} keeps its marker and emits one event`, async () => {
|
|
402
|
+
const { repo } = await twoVerifiedWorkers();
|
|
403
|
+
const originalAppend = fsPromises.appendFile;
|
|
404
|
+
const originalReaddir = fsPromises.readdir;
|
|
405
|
+
let completed = false;
|
|
406
|
+
try {
|
|
407
|
+
const cfg = await S.readTeamConfig('audit', repo);
|
|
408
|
+
assert.ok(cfg);
|
|
409
|
+
cfg.workers[0].pid = process.pid;
|
|
410
|
+
await S.saveTeamConfig(cfg, repo);
|
|
411
|
+
const task = await S.createTask('audit', { subject: 'Research', description: 'Concurrent completion', status: 'pending', owner: 'worker-2' }, repo);
|
|
412
|
+
const previous = await S.readMonitorSnapshot('audit', repo);
|
|
413
|
+
assert.ok(previous);
|
|
414
|
+
previous.taskStatusById[task.id] = 'pending';
|
|
415
|
+
await S.writeMonitorSnapshot('audit', previous, repo);
|
|
416
|
+
const finish = async () => {
|
|
417
|
+
completed = true;
|
|
418
|
+
const claim = await S.claimTask('audit', task.id, 'worker-2', null, repo);
|
|
419
|
+
assert.ok(claim.ok);
|
|
420
|
+
assert.ok((await S.transitionTaskStatus('audit', task.id, 'in_progress', 'completed', claim.claimToken, repo, { result: 'Research completed' })).ok);
|
|
421
|
+
};
|
|
422
|
+
fsPromises.appendFile = async (...args) => {
|
|
423
|
+
await originalAppend(...args);
|
|
424
|
+
if (boundary === 'integration' && !completed && String(args[1]).includes('"type":"worker_merge_applied"'))
|
|
425
|
+
await finish();
|
|
426
|
+
};
|
|
427
|
+
fsPromises.readdir = (async (...args) => {
|
|
428
|
+
if (boundary === 'task-read' && !completed && String(args[0]) === join(repo, '.omx/state/team/audit/tasks'))
|
|
429
|
+
await finish();
|
|
430
|
+
return originalReaddir(...args);
|
|
431
|
+
});
|
|
432
|
+
syncBuiltinESMExports();
|
|
433
|
+
await monitorTeam('audit', repo);
|
|
434
|
+
fsPromises.appendFile = originalAppend;
|
|
435
|
+
fsPromises.readdir = originalReaddir;
|
|
436
|
+
syncBuiltinESMExports();
|
|
437
|
+
assert.equal(completed, true);
|
|
438
|
+
assert.equal((await S.readMonitorSnapshot('audit', repo))?.completedEventTaskIds[task.id], true);
|
|
439
|
+
await monitorTeam('audit', repo);
|
|
440
|
+
const events = await readTeamEvents('audit', repo);
|
|
441
|
+
assert.equal(events.filter(event => event.type === 'task_completed' && event.task_id === task.id).length, 1);
|
|
442
|
+
}
|
|
443
|
+
finally {
|
|
444
|
+
fsPromises.appendFile = originalAppend;
|
|
445
|
+
fsPromises.readdir = originalReaddir;
|
|
446
|
+
syncBuiltinESMExports();
|
|
447
|
+
await rm(repo, { recursive: true, force: true });
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
for (const boundary of ['git-operation', 'task-corruption']) {
|
|
452
|
+
test(`shutdown preserves state when ${boundary} appears after preflight`, async () => {
|
|
453
|
+
const { repo, wt } = await fixture();
|
|
454
|
+
const originalRename = fsPromises.rename;
|
|
455
|
+
const originalLink = fsPromises.link;
|
|
456
|
+
let injected = false;
|
|
457
|
+
let marker = '';
|
|
458
|
+
try {
|
|
459
|
+
git(wt, 'checkout', '--detach');
|
|
460
|
+
const cfg = await S.readTeamConfig('audit', repo);
|
|
461
|
+
assert.ok(cfg);
|
|
462
|
+
cfg.workers[0].worktree_detached = true;
|
|
463
|
+
cfg.workers[0].worktree_branch = undefined;
|
|
464
|
+
await S.saveTeamConfig(cfg, repo);
|
|
465
|
+
await addWorkerCommit(wt);
|
|
466
|
+
const task = await complete(repo, wt);
|
|
467
|
+
await monitorTeam('audit', repo);
|
|
468
|
+
const path = join(repo, '.omx/state/team/audit/tasks', `task-${task.id}.json`);
|
|
469
|
+
fsPromises.rename = async (...args) => {
|
|
470
|
+
await originalRename(...args);
|
|
471
|
+
if (boundary === 'git-operation' && !injected && String(args[0]) === join(wt, '.omx/evidence/handoff.json')) {
|
|
472
|
+
injected = true;
|
|
473
|
+
marker = beginCleanManualMerge(wt);
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
fsPromises.link = async (...args) => {
|
|
477
|
+
await originalLink(...args);
|
|
478
|
+
if (boundary === 'task-corruption' && !injected && String(args[1]) === join(wt, '.omx/diff.md')) {
|
|
479
|
+
injected = true;
|
|
480
|
+
await writeFile(path, '{"broken":');
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
syncBuiltinESMExports();
|
|
484
|
+
await assert.rejects(shutdownTeam('audit', repo), /git_operation_in_progress|team_task_read_failed/);
|
|
485
|
+
assert.equal(injected, true);
|
|
486
|
+
assert.equal(existsSync(wt), true);
|
|
487
|
+
assert.equal(existsSync(path), true);
|
|
488
|
+
if (boundary === 'git-operation')
|
|
489
|
+
assert.equal(existsSync(marker), true);
|
|
490
|
+
else
|
|
491
|
+
assert.equal(await readFile(path, 'utf8'), '{"broken":');
|
|
492
|
+
}
|
|
493
|
+
finally {
|
|
494
|
+
fsPromises.rename = originalRename;
|
|
495
|
+
fsPromises.link = originalLink;
|
|
496
|
+
syncBuiltinESMExports();
|
|
497
|
+
await rm(repo, { recursive: true, force: true });
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
test('guarded rollback rechecks Git operations after archiving evidence', async () => {
|
|
502
|
+
const { repo, wt } = await fixture();
|
|
503
|
+
const original = fsPromises.rename;
|
|
504
|
+
let marker = '';
|
|
505
|
+
try {
|
|
506
|
+
await addWorkerCommit(wt);
|
|
507
|
+
await complete(repo, wt);
|
|
508
|
+
fsPromises.rename = async (...args) => {
|
|
509
|
+
await original(...args);
|
|
510
|
+
if (!marker && String(args[0]) === join(wt, '.omx/evidence/handoff.json'))
|
|
511
|
+
marker = beginCleanManualMerge(wt);
|
|
512
|
+
};
|
|
513
|
+
syncBuiltinESMExports();
|
|
514
|
+
await assert.rejects(rollbackProvisionedWorktrees([{
|
|
515
|
+
enabled: true, repoRoot: repo, worktreePath: wt, branchName: 'audit-worker',
|
|
516
|
+
detached: false, created: true, reused: false, createdBranch: false,
|
|
517
|
+
}], { force: false }), /git_operation_in_progress/);
|
|
518
|
+
assert.ok(marker && existsSync(marker));
|
|
519
|
+
assert.equal(await readFile(join(wt, 'worker.js'), 'utf8'), 'export const answer = 42;\n');
|
|
520
|
+
}
|
|
521
|
+
finally {
|
|
522
|
+
fsPromises.rename = original;
|
|
523
|
+
syncBuiltinESMExports();
|
|
524
|
+
await rm(repo, { recursive: true, force: true });
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
for (const failure of ['corrupt', 'missing']) {
|
|
528
|
+
test(`leader stop preserves actionable work when task state is ${failure}`, async () => {
|
|
529
|
+
const { repo } = await fixture();
|
|
530
|
+
try {
|
|
531
|
+
const task = await S.createTask('audit', { subject: 'Unfinished', description: 'Still pending', status: 'pending' }, repo);
|
|
532
|
+
await S.writeMonitorSnapshot('audit', {
|
|
533
|
+
taskStatusById: { [task.id]: 'pending' }, workerAliveByName: { 'worker-1': true },
|
|
534
|
+
workerStateByName: { 'worker-1': 'idle' }, workerTurnCountByName: {}, workerTaskIdByName: {},
|
|
535
|
+
mailboxNotifiedByMessageId: {}, completedEventTaskIds: {},
|
|
536
|
+
}, repo);
|
|
537
|
+
if (failure === 'corrupt')
|
|
538
|
+
await writeFile(join(repo, '.omx/state/team/audit/tasks', `task-${task.id}.json`), '{"broken":');
|
|
539
|
+
else
|
|
540
|
+
await rename(join(repo, '.omx/state/team/audit/tasks'), join(repo, '.omx/state/team/audit/tasks.saved'));
|
|
541
|
+
const state = await S.markTeamLeaderStopObserved('audit', repo, 'leader');
|
|
542
|
+
assert.equal(state.leader_session_active, false);
|
|
543
|
+
assert.equal(state.work_remaining, true);
|
|
544
|
+
assert.equal(state.leader_decision_state, 'still_actionable');
|
|
545
|
+
assert.equal(state.leader_attention_pending, true);
|
|
546
|
+
assert.ok(state.attention_reasons.includes('task_state_unavailable'));
|
|
547
|
+
}
|
|
548
|
+
finally {
|
|
549
|
+
await rm(repo, { recursive: true, force: true });
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
//# sourceMappingURL=p1-safety.test.js.map
|