@memnexus-ai/mx-agent-cli 0.1.232 → 0.1.233
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/dist/__tests__/behavioral-extraction.test.js +93 -0
- package/dist/__tests__/behavioral-extraction.test.js.map +1 -1
- package/dist/__tests__/behavioral-injection.test.d.ts +13 -0
- package/dist/__tests__/behavioral-injection.test.d.ts.map +1 -0
- package/dist/__tests__/behavioral-injection.test.js +384 -0
- package/dist/__tests__/behavioral-injection.test.js.map +1 -0
- package/dist/__tests__/bootstrap-behavioral-contract.test.d.ts +18 -0
- package/dist/__tests__/bootstrap-behavioral-contract.test.d.ts.map +1 -0
- package/dist/__tests__/bootstrap-behavioral-contract.test.js +101 -0
- package/dist/__tests__/bootstrap-behavioral-contract.test.js.map +1 -0
- package/dist/__tests__/provision-behavioral-contract.test.d.ts +13 -0
- package/dist/__tests__/provision-behavioral-contract.test.d.ts.map +1 -0
- package/dist/__tests__/provision-behavioral-contract.test.js +454 -0
- package/dist/__tests__/provision-behavioral-contract.test.js.map +1 -0
- package/dist/__tests__/provision-copy-containment.test.d.ts +19 -0
- package/dist/__tests__/provision-copy-containment.test.d.ts.map +1 -0
- package/dist/__tests__/provision-copy-containment.test.js +187 -0
- package/dist/__tests__/provision-copy-containment.test.js.map +1 -0
- package/dist/__tests__/provision-teambuilder-flow.test.d.ts +22 -0
- package/dist/__tests__/provision-teambuilder-flow.test.d.ts.map +1 -0
- package/dist/__tests__/provision-teambuilder-flow.test.js +165 -0
- package/dist/__tests__/provision-teambuilder-flow.test.js.map +1 -0
- package/dist/__tests__/provision-write-integrity.test.d.ts +18 -0
- package/dist/__tests__/provision-write-integrity.test.d.ts.map +1 -0
- package/dist/__tests__/provision-write-integrity.test.js +141 -0
- package/dist/__tests__/provision-write-integrity.test.js.map +1 -0
- package/dist/__tests__/startup-report.test.js +3 -3
- package/dist/__tests__/startup-report.test.js.map +1 -1
- package/dist/commands/bootstrap.d.ts +2 -0
- package/dist/commands/bootstrap.d.ts.map +1 -1
- package/dist/commands/bootstrap.js +15 -1
- package/dist/commands/bootstrap.js.map +1 -1
- package/dist/commands/create.d.ts +188 -0
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +606 -23
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/new.d.ts +2 -0
- package/dist/commands/new.d.ts.map +1 -1
- package/dist/commands/new.js +6 -1
- package/dist/commands/new.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/behavioral-injection.d.ts +144 -0
- package/dist/lib/behavioral-injection.d.ts.map +1 -0
- package/dist/lib/behavioral-injection.js +438 -0
- package/dist/lib/behavioral-injection.js.map +1 -0
- package/dist/lib/claude.d.ts +49 -7
- package/dist/lib/claude.d.ts.map +1 -1
- package/dist/lib/claude.js +62 -82
- package/dist/lib/claude.js.map +1 -1
- package/dist/lib/templates.d.ts +1 -1
- package/dist/lib/templates.d.ts.map +1 -1
- package/dist/lib/templates.js +2 -0
- package/dist/lib/templates.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provision-copy-containment.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/provision-copy-containment.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Step-6b / catalog copy containment (#4541 security review round 4; the
|
|
3
|
+
* underlying defect is pre-existing and tracked as #4571).
|
|
4
|
+
*
|
|
5
|
+
* These tests exercise the REAL filesystem helpers rather than asserting on a
|
|
6
|
+
* refusal message, because the property that matters is "no byte was written
|
|
7
|
+
* outside the destination root", and only a filesystem check proves that.
|
|
8
|
+
*
|
|
9
|
+
* The demonstrated exploit: a team-builder running inside its own worktree plants
|
|
10
|
+
* a payload in its own tree — trivially passing SOURCE containment, since that
|
|
11
|
+
* tree is a legitimately allowed root — then passes
|
|
12
|
+
* `--roleguide ../victim-team/.git/hooks/pre-commit`. The old destination was
|
|
13
|
+
* `join(worktreePath, roleguide)`, and `join` NORMALISES `..` rather than
|
|
14
|
+
* rejecting it, so the file landed in another team's worktree. `copyFileSync`
|
|
15
|
+
* preserved the source mode, so a 0755 source arrived as an executable git hook
|
|
16
|
+
* that ran on the victim's next commit.
|
|
17
|
+
*/
|
|
18
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
19
|
+
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, existsSync, statSync, symlinkSync, readdirSync, } from 'fs';
|
|
20
|
+
import { join } from 'path';
|
|
21
|
+
import { tmpdir } from 'os';
|
|
22
|
+
import { __testing } from '../commands/create.js';
|
|
23
|
+
const { reanchorContained, writeContained } = __testing;
|
|
24
|
+
let base;
|
|
25
|
+
let srcRoot;
|
|
26
|
+
let destRoot;
|
|
27
|
+
let victim;
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
base = mkdtempSync(join(tmpdir(), 'mx-copy-contain-'));
|
|
30
|
+
srcRoot = join(base, 'builder-worktree');
|
|
31
|
+
destRoot = join(base, 'new-worktree');
|
|
32
|
+
victim = join(base, 'victim-team');
|
|
33
|
+
mkdirSync(srcRoot, { recursive: true });
|
|
34
|
+
mkdirSync(destRoot, { recursive: true });
|
|
35
|
+
mkdirSync(join(victim, '.git', 'hooks'), { recursive: true });
|
|
36
|
+
});
|
|
37
|
+
afterEach(() => {
|
|
38
|
+
rmSync(base, { recursive: true, force: true });
|
|
39
|
+
});
|
|
40
|
+
describe('reanchorContained', () => {
|
|
41
|
+
it('re-anchors a source path by its position relative to its validated root', () => {
|
|
42
|
+
const src = join(srcRoot, 'mx-agent-system/roleguides/x-leader.md');
|
|
43
|
+
mkdirSync(join(srcRoot, 'mx-agent-system/roleguides'), { recursive: true });
|
|
44
|
+
writeFileSync(src, 'x');
|
|
45
|
+
const r = reanchorContained(srcRoot, src, destRoot);
|
|
46
|
+
expect(r.ok).toBe(true);
|
|
47
|
+
if (!r.ok)
|
|
48
|
+
return;
|
|
49
|
+
expect(r.rel).toBe('mx-agent-system/roleguides/x-leader.md');
|
|
50
|
+
expect(r.dest).toBe(join(destRoot, 'mx-agent-system/roleguides/x-leader.md'));
|
|
51
|
+
});
|
|
52
|
+
it('REFUSES a source that is not inside its declared root', () => {
|
|
53
|
+
const outside = join(base, 'elsewhere.md');
|
|
54
|
+
writeFileSync(outside, 'x');
|
|
55
|
+
const r = reanchorContained(srcRoot, outside, destRoot);
|
|
56
|
+
expect(r.ok).toBe(false);
|
|
57
|
+
if (r.ok)
|
|
58
|
+
return;
|
|
59
|
+
expect(r.detail).toContain('not inside its validated root');
|
|
60
|
+
});
|
|
61
|
+
it('the destination can never escape the destination root', () => {
|
|
62
|
+
// Even a source path deliberately built to look like traversal cannot produce
|
|
63
|
+
// an escaping destination, because the destination is derived from `relative`
|
|
64
|
+
// and re-verified, never from the caller's string.
|
|
65
|
+
const src = join(srcRoot, 'a/b/c.md');
|
|
66
|
+
mkdirSync(join(srcRoot, 'a/b'), { recursive: true });
|
|
67
|
+
writeFileSync(src, 'x');
|
|
68
|
+
const r = reanchorContained(srcRoot, src, destRoot);
|
|
69
|
+
expect(r.ok).toBe(true);
|
|
70
|
+
if (!r.ok)
|
|
71
|
+
return;
|
|
72
|
+
expect(r.dest.startsWith(destRoot + '/')).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
describe('writeContained', () => {
|
|
76
|
+
it('writes mode 0644, never inheriting an executable source mode', () => {
|
|
77
|
+
// Mode inheritance is what turns a path bug into code execution.
|
|
78
|
+
const src = join(srcRoot, 'payload.sh');
|
|
79
|
+
writeFileSync(src, '#!/bin/sh\nid\n', { mode: 0o755 });
|
|
80
|
+
expect(statSync(src).mode & 0o777).toBe(0o755);
|
|
81
|
+
const dest = join(destRoot, 'copied.md');
|
|
82
|
+
const w = writeContained(dest, destRoot, readFileSync(src, 'utf-8'));
|
|
83
|
+
expect(w.ok).toBe(true);
|
|
84
|
+
expect(statSync(dest).mode & 0o777).toBe(0o644);
|
|
85
|
+
expect(statSync(dest).mode & 0o111).toBe(0); // no execute bit anywhere
|
|
86
|
+
});
|
|
87
|
+
it('REFUSES a symlinked parent AND creates no directory outside the root', () => {
|
|
88
|
+
// `mkdirSync(..., { recursive: true })` follows symlinked components. An
|
|
89
|
+
// earlier revision refused the WRITE correctly but had already CREATED the
|
|
90
|
+
// directories, so `victim/a/b` appeared outside the root. No content and no
|
|
91
|
+
// mode, but a directory where another team's process expects a file — e.g.
|
|
92
|
+
// `<victim>/CLAUDE.local.md/` — is an EISDIR denial of service on that team's
|
|
93
|
+
// session start. Containment of the deepest existing ancestor is now verified
|
|
94
|
+
// BEFORE anything is created.
|
|
95
|
+
symlinkSync(victim, join(destRoot, 'linked'));
|
|
96
|
+
const dest = join(destRoot, 'linked', 'a', 'b', 'pre-commit');
|
|
97
|
+
const w = writeContained(dest, destRoot, 'payload');
|
|
98
|
+
expect(w.ok).toBe(false);
|
|
99
|
+
if (w.ok)
|
|
100
|
+
return;
|
|
101
|
+
expect(w.detail).toContain('refusing to create any directory');
|
|
102
|
+
// The property that matters: nothing was created in the victim's tree.
|
|
103
|
+
expect(existsSync(join(victim, 'a'))).toBe(false);
|
|
104
|
+
expect(readdirSync(victim).sort()).toEqual(['.git']);
|
|
105
|
+
});
|
|
106
|
+
it('REFUSES a symlinked-to-a-file destination directory without creating anything', () => {
|
|
107
|
+
// Same class, different shape: the symlink is the immediate parent.
|
|
108
|
+
symlinkSync(join(victim, '.git', 'hooks'), join(destRoot, 'hooks'));
|
|
109
|
+
const dest = join(destRoot, 'hooks', 'pre-commit');
|
|
110
|
+
const w = writeContained(dest, destRoot, 'payload');
|
|
111
|
+
expect(w.ok).toBe(false);
|
|
112
|
+
expect(existsSync(join(victim, '.git', 'hooks', 'pre-commit'))).toBe(false);
|
|
113
|
+
expect(readdirSync(join(victim, '.git', 'hooks'))).toEqual([]);
|
|
114
|
+
});
|
|
115
|
+
it('REFUSES a DANGLING symlink at the final component — and creates nothing outside destRoot', () => {
|
|
116
|
+
// MUST FIX, review round 5. `writeFileSync` opened with O_CREAT and neither
|
|
117
|
+
// O_NOFOLLOW nor O_EXCL, so a symlink AT THE FINAL COMPONENT was followed:
|
|
118
|
+
// both pathIsInside checks pass because the lexical path is inside the root,
|
|
119
|
+
// and only the resolution escapes.
|
|
120
|
+
//
|
|
121
|
+
// The caller's `existsSync(dest)` guard is NOT a defence and this is why:
|
|
122
|
+
// existsSync FOLLOWS the link, so a DANGLING link reports absent and
|
|
123
|
+
// execution proceeds straight to the write.
|
|
124
|
+
const victimFile = join(victim, '.git', 'hooks', 'pre-commit');
|
|
125
|
+
expect(existsSync(victimFile)).toBe(false);
|
|
126
|
+
const dest = join(destRoot, 'roleguide.md');
|
|
127
|
+
symlinkSync(victimFile, dest); // dangling: target does not exist yet
|
|
128
|
+
expect(existsSync(dest)).toBe(false); // existsSync follows → reports absent
|
|
129
|
+
const w = writeContained(dest, destRoot, 'ATTACKER CONTROLLED BYTES');
|
|
130
|
+
expect(w.ok).toBe(false);
|
|
131
|
+
if (w.ok)
|
|
132
|
+
return;
|
|
133
|
+
expect(w.detail).toMatch(/EEXIST|symbolic link/);
|
|
134
|
+
// The property that matters: nothing was created outside destRoot.
|
|
135
|
+
expect(existsSync(victimFile)).toBe(false);
|
|
136
|
+
expect(readdirSync(join(victim, '.git', 'hooks'))).toEqual([]);
|
|
137
|
+
});
|
|
138
|
+
it('REFUSES a LIVE symlink at the final component without overwriting the target', () => {
|
|
139
|
+
const victimFile = join(victim, 'existing.md');
|
|
140
|
+
writeFileSync(victimFile, 'ORIGINAL');
|
|
141
|
+
const dest = join(destRoot, 'roleguide.md');
|
|
142
|
+
symlinkSync(victimFile, dest);
|
|
143
|
+
const w = writeContained(dest, destRoot, 'ATTACKER CONTROLLED BYTES');
|
|
144
|
+
expect(w.ok).toBe(false);
|
|
145
|
+
expect(readFileSync(victimFile, 'utf-8')).toBe('ORIGINAL');
|
|
146
|
+
});
|
|
147
|
+
it('REFUSES to overwrite an existing regular file (EEXIST, atomic)', () => {
|
|
148
|
+
const dest = join(destRoot, 'roleguide.md');
|
|
149
|
+
writeFileSync(dest, 'ALREADY HERE');
|
|
150
|
+
const w = writeContained(dest, destRoot, 'NEW BYTES');
|
|
151
|
+
expect(w.ok).toBe(false);
|
|
152
|
+
if (w.ok)
|
|
153
|
+
return;
|
|
154
|
+
expect(w.detail).toContain('EEXIST');
|
|
155
|
+
expect(readFileSync(dest, 'utf-8')).toBe('ALREADY HERE');
|
|
156
|
+
});
|
|
157
|
+
it('writes normally inside the destination root', () => {
|
|
158
|
+
const dest = join(destRoot, 'mx-agent-system', 'roleguides', 'ok.md');
|
|
159
|
+
const w = writeContained(dest, destRoot, 'hello');
|
|
160
|
+
expect(w.ok).toBe(true);
|
|
161
|
+
expect(readFileSync(dest, 'utf-8')).toBe('hello');
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
describe('end to end: the demonstrated exploit writes nothing outside the worktree', () => {
|
|
165
|
+
it('a ../victim-team/.git/hooks/pre-commit destination is never produced', () => {
|
|
166
|
+
// Source is legitimately inside the builder's own worktree — source
|
|
167
|
+
// containment alone does not stop this.
|
|
168
|
+
const payload = join(srcRoot, 'payload.sh');
|
|
169
|
+
writeFileSync(payload, '#!/bin/sh\nid > /tmp/pwned\n', { mode: 0o755 });
|
|
170
|
+
// The old code did: join(destRoot, '../victim-team/.git/hooks/pre-commit')
|
|
171
|
+
const oldStyleDestination = join(destRoot, '../victim-team/.git/hooks/pre-commit');
|
|
172
|
+
expect(oldStyleDestination).toBe(join(victim, '.git/hooks/pre-commit')); // join normalises ..
|
|
173
|
+
// The new derivation ignores the operator string entirely.
|
|
174
|
+
const r = reanchorContained(srcRoot, payload, destRoot);
|
|
175
|
+
expect(r.ok).toBe(true);
|
|
176
|
+
if (!r.ok)
|
|
177
|
+
return;
|
|
178
|
+
expect(r.dest).toBe(join(destRoot, 'payload.sh'));
|
|
179
|
+
expect(r.dest).not.toContain('victim-team');
|
|
180
|
+
const w = writeContained(r.dest, destRoot, readFileSync(payload, 'utf-8'));
|
|
181
|
+
expect(w.ok).toBe(true);
|
|
182
|
+
// The victim's hook was never created, and the copy is not executable.
|
|
183
|
+
expect(existsSync(join(victim, '.git', 'hooks', 'pre-commit'))).toBe(false);
|
|
184
|
+
expect(statSync(r.dest).mode & 0o111).toBe(0);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
//# sourceMappingURL=provision-copy-containment.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provision-copy-containment.test.js","sourceRoot":"","sources":["../../src/__tests__/provision-copy-containment.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,EACL,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,EAC3D,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,GAC/C,MAAM,IAAI,CAAC;AACZ,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,MAAM,EAAE,iBAAiB,EAAE,cAAc,EAAE,GAAG,SAAS,CAAC;AAExD,IAAI,IAAY,CAAC;AACjB,IAAI,OAAe,CAAC;AACpB,IAAI,QAAgB,CAAC;AACrB,IAAI,MAAc,CAAC;AAEnB,UAAU,CAAC,GAAG,EAAE;IACd,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,kBAAkB,CAAC,CAAC,CAAC;IACvD,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,k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AAO,CAAC,CAAC,CAAC;QAC3E,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAExB,uEAAuE;QACvE,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC5E,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The team-builder Step 6a flow — the genuine TWO-ROOT case (#4541 review round 6).
|
|
3
|
+
*
|
|
4
|
+
* `team-builder.md:371`: the builder drafts a roleguide in ITS OWN worktree and
|
|
5
|
+
* runs `mx-agent provision` from there, before the file reaches the base branch.
|
|
6
|
+
* Two allowed roots are live at once, and they NEST — `.worktrees/` is inside the
|
|
7
|
+
* project root — so the roleguide is inside both.
|
|
8
|
+
*
|
|
9
|
+
* Root selection took the FIRST matching root. The project root was pushed first,
|
|
10
|
+
* so it always won, and `relative()` produced
|
|
11
|
+
* `.worktrees/builder-wt/mx-agent-system/roleguides/x.md`: contained, but the
|
|
12
|
+
* wrong location. Round 4 wrote silently to that garbage path; round 5's
|
|
13
|
+
* roleguides-prefix check turned it into a refusal — correct behaviour from the
|
|
14
|
+
* check, and it exposed that the new team was shipping with NO roleguide at all.
|
|
15
|
+
*
|
|
16
|
+
* Nothing caught it because every other provisioning test passes
|
|
17
|
+
* `projectRoot: root` with the roleguide directly beneath it, i.e. ONE root. This
|
|
18
|
+
* file exists to cover the two-root shape, and it asserts the file EXISTS ON DISK
|
|
19
|
+
* at the right path rather than asserting that a warning was absent.
|
|
20
|
+
*/
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=provision-teambuilder-flow.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provision-teambuilder-flow.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/provision-teambuilder-flow.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The team-builder Step 6a flow — the genuine TWO-ROOT case (#4541 review round 6).
|
|
3
|
+
*
|
|
4
|
+
* `team-builder.md:371`: the builder drafts a roleguide in ITS OWN worktree and
|
|
5
|
+
* runs `mx-agent provision` from there, before the file reaches the base branch.
|
|
6
|
+
* Two allowed roots are live at once, and they NEST — `.worktrees/` is inside the
|
|
7
|
+
* project root — so the roleguide is inside both.
|
|
8
|
+
*
|
|
9
|
+
* Root selection took the FIRST matching root. The project root was pushed first,
|
|
10
|
+
* so it always won, and `relative()` produced
|
|
11
|
+
* `.worktrees/builder-wt/mx-agent-system/roleguides/x.md`: contained, but the
|
|
12
|
+
* wrong location. Round 4 wrote silently to that garbage path; round 5's
|
|
13
|
+
* roleguides-prefix check turned it into a refusal — correct behaviour from the
|
|
14
|
+
* check, and it exposed that the new team was shipping with NO roleguide at all.
|
|
15
|
+
*
|
|
16
|
+
* Nothing caught it because every other provisioning test passes
|
|
17
|
+
* `projectRoot: root` with the roleguide directly beneath it, i.e. ONE root. This
|
|
18
|
+
* file exists to cover the two-root shape, and it asserts the file EXISTS ON DISK
|
|
19
|
+
* at the right path rather than asserting that a warning was absent.
|
|
20
|
+
*/
|
|
21
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
22
|
+
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, existsSync, statSync, } from 'fs';
|
|
23
|
+
import { join, dirname } from 'path';
|
|
24
|
+
import { tmpdir } from 'os';
|
|
25
|
+
const assignSlot = vi.fn(() => 0);
|
|
26
|
+
const createGitWorktree = vi.fn((worktreePath) => {
|
|
27
|
+
mkdirSync(worktreePath, { recursive: true });
|
|
28
|
+
});
|
|
29
|
+
vi.mock('../lib/worktree.js', () => ({
|
|
30
|
+
findProjectRoot: vi.fn(() => '/unused'),
|
|
31
|
+
assignSlot: (...a) => assignSlot(...a),
|
|
32
|
+
getCurrentBranch: vi.fn(() => 'worktree/x'),
|
|
33
|
+
fetchOrigin: vi.fn(),
|
|
34
|
+
createGitWorktree: (worktreePath, ..._rest) => createGitWorktree(worktreePath),
|
|
35
|
+
addToGitSafeDirectory: vi.fn(),
|
|
36
|
+
createHuskySymlink: vi.fn(),
|
|
37
|
+
generateBranchName: vi.fn((s) => `worktree/${s}`),
|
|
38
|
+
generateWorktreeDirName: vi.fn((s) => `${s}-20260101`),
|
|
39
|
+
}));
|
|
40
|
+
const logWarning = vi.fn();
|
|
41
|
+
vi.mock('../lib/claude.js', () => ({
|
|
42
|
+
syncClaudeConfig: vi.fn(),
|
|
43
|
+
deployClaudeMd: vi.fn(),
|
|
44
|
+
writeClaudeLocal: vi.fn(),
|
|
45
|
+
logSuccess: vi.fn(),
|
|
46
|
+
logWarning: (...a) => logWarning(...a),
|
|
47
|
+
logDim: vi.fn(),
|
|
48
|
+
}));
|
|
49
|
+
vi.mock('../lib/catalog.js', () => ({
|
|
50
|
+
writeTeamCatalog: vi.fn(),
|
|
51
|
+
slugToDisplayName: vi.fn((s) => s),
|
|
52
|
+
}));
|
|
53
|
+
vi.mock('../lib/memory.js', () => ({
|
|
54
|
+
isMxAvailable: vi.fn(() => false),
|
|
55
|
+
bootstrapTeamMemories: vi.fn(),
|
|
56
|
+
logMemoryResult: vi.fn(),
|
|
57
|
+
teamMemorySpecs: vi.fn(() => []),
|
|
58
|
+
logManualMemoryCommands: vi.fn(),
|
|
59
|
+
}));
|
|
60
|
+
vi.mock('../lib/project-config.js', () => ({
|
|
61
|
+
loadProjectConfig: vi.fn(() => ({})),
|
|
62
|
+
resolveProjectConfig: vi.fn(() => ({
|
|
63
|
+
worktreeDir: '.worktrees',
|
|
64
|
+
baseBranch: 'main',
|
|
65
|
+
configSource: 'mx-agent-system/agent-config',
|
|
66
|
+
teamsDir: 'mx-agent-system/teams',
|
|
67
|
+
roleguidesDir: 'mx-agent-system/roleguides',
|
|
68
|
+
projectSlug: '',
|
|
69
|
+
})),
|
|
70
|
+
}));
|
|
71
|
+
vi.mock('../lib/config-generation.js', () => ({ checkConfigGeneration: vi.fn() }));
|
|
72
|
+
import { runCreate } from '../commands/create.js';
|
|
73
|
+
import { __testing } from '../commands/create.js';
|
|
74
|
+
import { BEHAVIORAL_START_MARKER, BEHAVIORAL_END_MARKER } from '../lib/behavioral-injection.js';
|
|
75
|
+
const RG_REL = 'mx-agent-system/roleguides/newteam-leader.md';
|
|
76
|
+
const ROLEGUIDE = [
|
|
77
|
+
'# New Team Roleguide',
|
|
78
|
+
'',
|
|
79
|
+
BEHAVIORAL_START_MARKER,
|
|
80
|
+
'## Decision Authority',
|
|
81
|
+
'',
|
|
82
|
+
'- Ship without asking when the data is clear.',
|
|
83
|
+
BEHAVIORAL_END_MARKER,
|
|
84
|
+
].join('\n');
|
|
85
|
+
let projectRoot;
|
|
86
|
+
let builderWorktree;
|
|
87
|
+
let cwdSpy;
|
|
88
|
+
beforeEach(() => {
|
|
89
|
+
projectRoot = mkdtempSync(join(tmpdir(), 'mx-tb-project-'));
|
|
90
|
+
// A worktree UNDER the project's configured worktree directory, containing a
|
|
91
|
+
// `.git` file exactly as a linked git worktree does.
|
|
92
|
+
builderWorktree = join(projectRoot, '.worktrees', 'team-builder-20260101');
|
|
93
|
+
mkdirSync(builderWorktree, { recursive: true });
|
|
94
|
+
writeFileSync(join(builderWorktree, '.git'), 'gitdir: /somewhere/.git/worktrees/team-builder\n');
|
|
95
|
+
// The project root is itself a git checkout.
|
|
96
|
+
mkdirSync(join(projectRoot, '.git'), { recursive: true });
|
|
97
|
+
// The drafted roleguide exists ONLY in the builder's worktree — it has not
|
|
98
|
+
// reached the base branch yet. This is the whole point of root #2.
|
|
99
|
+
mkdirSync(dirname(join(builderWorktree, RG_REL)), { recursive: true });
|
|
100
|
+
writeFileSync(join(builderWorktree, RG_REL), ROLEGUIDE);
|
|
101
|
+
vi.clearAllMocks();
|
|
102
|
+
vi.spyOn(console, 'log').mockImplementation(() => { });
|
|
103
|
+
vi.spyOn(console, 'error').mockImplementation(() => { });
|
|
104
|
+
cwdSpy = vi.spyOn(process, 'cwd').mockReturnValue(builderWorktree);
|
|
105
|
+
});
|
|
106
|
+
afterEach(() => {
|
|
107
|
+
cwdSpy.mockRestore();
|
|
108
|
+
rmSync(projectRoot, { recursive: true, force: true });
|
|
109
|
+
vi.restoreAllMocks();
|
|
110
|
+
});
|
|
111
|
+
describe('allowedRoleguideRoots — nesting', () => {
|
|
112
|
+
it('returns the builder worktree BEFORE the project root (most specific first)', () => {
|
|
113
|
+
const roots = __testing.allowedRoleguideRoots(projectRoot, '.worktrees');
|
|
114
|
+
expect(roots.length).toBe(2);
|
|
115
|
+
// Deepest first: if the project root came first it would claim every file in
|
|
116
|
+
// every worktree, since .worktrees/ is inside it.
|
|
117
|
+
expect(roots[0]).toContain('.worktrees');
|
|
118
|
+
expect(roots[1]).not.toContain('.worktrees');
|
|
119
|
+
expect(roots[0].length).toBeGreaterThan(roots[1].length);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
describe('team-builder Step 6a: provisioning from the builder worktree', () => {
|
|
123
|
+
it('copies the roleguide to the correct path in the new worktree', async () => {
|
|
124
|
+
await runCreate({
|
|
125
|
+
roleguide: RG_REL,
|
|
126
|
+
name: 'newteam',
|
|
127
|
+
projectRoot,
|
|
128
|
+
});
|
|
129
|
+
const newWorktree = join(projectRoot, '.worktrees', 'newteam-20260101');
|
|
130
|
+
const copied = join(newWorktree, RG_REL);
|
|
131
|
+
// The assertion that matters: the file is ON DISK at the right path.
|
|
132
|
+
expect(existsSync(copied)).toBe(true);
|
|
133
|
+
expect(readFileSync(copied, 'utf-8')).toBe(ROLEGUIDE);
|
|
134
|
+
expect(statSync(copied).mode & 0o777).toBe(0o644);
|
|
135
|
+
// And NOT at the wrong, project-root-relative path the first-match bug produced.
|
|
136
|
+
expect(existsSync(join(newWorktree, '.worktrees'))).toBe(false);
|
|
137
|
+
});
|
|
138
|
+
it('does not warn about the copy', async () => {
|
|
139
|
+
await runCreate({ roleguide: RG_REL, name: 'newteam', projectRoot });
|
|
140
|
+
const warned = logWarning.mock.calls.map((c) => String(c[0])).join('\n');
|
|
141
|
+
expect(warned).not.toContain('Refusing to copy');
|
|
142
|
+
expect(warned).not.toContain('a roleguide must live under');
|
|
143
|
+
});
|
|
144
|
+
it('an absolute path into the builder worktree works the same way', async () => {
|
|
145
|
+
await runCreate({
|
|
146
|
+
roleguide: join(builderWorktree, RG_REL),
|
|
147
|
+
name: 'newteam',
|
|
148
|
+
projectRoot,
|
|
149
|
+
});
|
|
150
|
+
const copied = join(projectRoot, '.worktrees', 'newteam-20260101', RG_REL);
|
|
151
|
+
expect(existsSync(copied)).toBe(true);
|
|
152
|
+
expect(readFileSync(copied, 'utf-8')).toBe(ROLEGUIDE);
|
|
153
|
+
});
|
|
154
|
+
it('still resolves from the project root when the file lives there', async () => {
|
|
155
|
+
// The builder worktree root must not break the ordinary single-root case.
|
|
156
|
+
rmSync(join(builderWorktree, RG_REL));
|
|
157
|
+
mkdirSync(dirname(join(projectRoot, RG_REL)), { recursive: true });
|
|
158
|
+
writeFileSync(join(projectRoot, RG_REL), ROLEGUIDE);
|
|
159
|
+
await runCreate({ roleguide: RG_REL, name: 'newteam', projectRoot });
|
|
160
|
+
const copied = join(projectRoot, '.worktrees', 'newteam-20260101', RG_REL);
|
|
161
|
+
expect(existsSync(copied)).toBe(true);
|
|
162
|
+
expect(readFileSync(copied, 'utf-8')).toBe(ROLEGUIDE);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
//# sourceMappingURL=provision-teambuilder-flow.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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M,CAAC,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC,CAAC;QACtC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACnE,aAAa,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;QAEpD,MAAM,SAAS,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;QAErE,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,CAAC,CAAC;QAC3E,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtC,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write integrity in `writeContained` (#4541 review round 6, hardening B and C).
|
|
3
|
+
*
|
|
4
|
+
* `write(2)` may return having written FEWER bytes than requested without
|
|
5
|
+
* throwing — ENOSPC is the realistic trigger. Discarding the return value reports
|
|
6
|
+
* a SUCCESSFUL COPY for a TRUNCATED file, and a roleguide truncated past its end
|
|
7
|
+
* marker is exactly the copy/injection divergence that threading the validated
|
|
8
|
+
* bytes through `raw` exists to prevent, reintroduced at the write side.
|
|
9
|
+
*
|
|
10
|
+
* Separately, on filesystems that defer flushing, the write error surfaces at
|
|
11
|
+
* `close(2)`; swallowing it reports a failed write as a successful copy.
|
|
12
|
+
*
|
|
13
|
+
* `fs` is mocked here so short writes and close failures can be forced
|
|
14
|
+
* deterministically. Everything except `writeSync`/`closeSync` delegates to the
|
|
15
|
+
* real module, so the containment logic under test is unmodified.
|
|
16
|
+
*/
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=provision-write-integrity.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provision-write-integrity.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/provision-write-integrity.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write integrity in `writeContained` (#4541 review round 6, hardening B and C).
|
|
3
|
+
*
|
|
4
|
+
* `write(2)` may return having written FEWER bytes than requested without
|
|
5
|
+
* throwing — ENOSPC is the realistic trigger. Discarding the return value reports
|
|
6
|
+
* a SUCCESSFUL COPY for a TRUNCATED file, and a roleguide truncated past its end
|
|
7
|
+
* marker is exactly the copy/injection divergence that threading the validated
|
|
8
|
+
* bytes through `raw` exists to prevent, reintroduced at the write side.
|
|
9
|
+
*
|
|
10
|
+
* Separately, on filesystems that defer flushing, the write error surfaces at
|
|
11
|
+
* `close(2)`; swallowing it reports a failed write as a successful copy.
|
|
12
|
+
*
|
|
13
|
+
* `fs` is mocked here so short writes and close failures can be forced
|
|
14
|
+
* deterministically. Everything except `writeSync`/`closeSync` delegates to the
|
|
15
|
+
* real module, so the containment logic under test is unmodified.
|
|
16
|
+
*/
|
|
17
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
18
|
+
import { mkdtempSync, rmSync, readFileSync, existsSync } from 'fs';
|
|
19
|
+
import { join } from 'path';
|
|
20
|
+
import { tmpdir } from 'os';
|
|
21
|
+
/** Bytes per writeSync call; 0 or negative simulates a stalled write. */
|
|
22
|
+
let chunkSize = Number.MAX_SAFE_INTEGER;
|
|
23
|
+
/** After this many successful writeSync calls, subsequent calls return 0. */
|
|
24
|
+
let stallAfterCalls = Number.MAX_SAFE_INTEGER;
|
|
25
|
+
let writeCalls = 0;
|
|
26
|
+
/** When set, closeSync throws this. */
|
|
27
|
+
let closeError = null;
|
|
28
|
+
vi.mock('fs', async (importOriginal) => {
|
|
29
|
+
const real = await importOriginal();
|
|
30
|
+
return {
|
|
31
|
+
...real,
|
|
32
|
+
default: real,
|
|
33
|
+
writeSync: (fd, buf, off, len) => {
|
|
34
|
+
if (chunkSize <= 0)
|
|
35
|
+
return chunkSize;
|
|
36
|
+
if (writeCalls >= stallAfterCalls)
|
|
37
|
+
return 0;
|
|
38
|
+
writeCalls += 1;
|
|
39
|
+
return real.writeSync(fd, buf, off, Math.min(len, chunkSize));
|
|
40
|
+
},
|
|
41
|
+
closeSync: (fd) => {
|
|
42
|
+
real.closeSync(fd);
|
|
43
|
+
if (closeError)
|
|
44
|
+
throw closeError;
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
import { __testing } from '../commands/create.js';
|
|
49
|
+
const { writeContained } = __testing;
|
|
50
|
+
let destRoot;
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
destRoot = mkdtempSync(join(tmpdir(), 'mx-write-integrity-'));
|
|
53
|
+
chunkSize = Number.MAX_SAFE_INTEGER;
|
|
54
|
+
stallAfterCalls = Number.MAX_SAFE_INTEGER;
|
|
55
|
+
writeCalls = 0;
|
|
56
|
+
closeError = null;
|
|
57
|
+
});
|
|
58
|
+
afterEach(() => {
|
|
59
|
+
rmSync(destRoot, { recursive: true, force: true });
|
|
60
|
+
vi.clearAllMocks();
|
|
61
|
+
});
|
|
62
|
+
describe('writeContained — short writes', () => {
|
|
63
|
+
it('loops until every byte is written when the kernel writes short', () => {
|
|
64
|
+
// 7 bytes at a time across a payload that needs many iterations, including a
|
|
65
|
+
// final partial chunk.
|
|
66
|
+
chunkSize = 7;
|
|
67
|
+
const content = `${'x'.repeat(5000)}\n<!-- behavioral-end -->\n`;
|
|
68
|
+
const dest = join(destRoot, 'rg.md');
|
|
69
|
+
const w = writeContained(dest, destRoot, content);
|
|
70
|
+
expect(w.ok).toBe(true);
|
|
71
|
+
expect(readFileSync(dest, 'utf-8')).toBe(content);
|
|
72
|
+
});
|
|
73
|
+
it('writes multi-byte UTF-8 correctly (byte offsets, not character offsets)', () => {
|
|
74
|
+
chunkSize = 3; // deliberately splits multi-byte sequences mid-character
|
|
75
|
+
const content = '# Rôle — “quoted” ✓\n<!-- behavioral-start -->\né\n<!-- behavioral-end -->\n';
|
|
76
|
+
const dest = join(destRoot, 'rg.md');
|
|
77
|
+
const w = writeContained(dest, destRoot, content);
|
|
78
|
+
expect(w.ok).toBe(true);
|
|
79
|
+
expect(readFileSync(dest, 'utf-8')).toBe(content);
|
|
80
|
+
});
|
|
81
|
+
it('REFUSES and names the byte count when the write stalls', () => {
|
|
82
|
+
chunkSize = 0; // write(2) returns 0 without throwing
|
|
83
|
+
const dest = join(destRoot, 'rg.md');
|
|
84
|
+
const w = writeContained(dest, destRoot, 'some content that will never land');
|
|
85
|
+
expect(w.ok).toBe(false);
|
|
86
|
+
if (w.ok)
|
|
87
|
+
return;
|
|
88
|
+
expect(w.detail).toContain('short write');
|
|
89
|
+
expect(w.detail).toContain('wrote 0 of');
|
|
90
|
+
expect(w.detail).toContain('may be truncated');
|
|
91
|
+
});
|
|
92
|
+
it('does not report success for a PARTIALLY written file', () => {
|
|
93
|
+
// One chunk lands, then the write stalls. The file exists (the exclusive open
|
|
94
|
+
// created it) and holds a prefix of the content — the caller must not be told
|
|
95
|
+
// the copy succeeded, because a roleguide truncated past its end marker is a
|
|
96
|
+
// silent divergence from the validated bytes.
|
|
97
|
+
chunkSize = 10;
|
|
98
|
+
stallAfterCalls = 1;
|
|
99
|
+
const content = 'A'.repeat(100);
|
|
100
|
+
const dest = join(destRoot, 'rg.md');
|
|
101
|
+
const w = writeContained(dest, destRoot, content);
|
|
102
|
+
expect(w.ok).toBe(false);
|
|
103
|
+
if (w.ok)
|
|
104
|
+
return;
|
|
105
|
+
expect(w.detail).toContain('wrote 10 of 100 bytes');
|
|
106
|
+
expect(existsSync(dest)).toBe(true);
|
|
107
|
+
const onDisk = readFileSync(dest, 'utf-8');
|
|
108
|
+
expect(onDisk).not.toBe(content);
|
|
109
|
+
expect(onDisk).toBe('A'.repeat(10));
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
describe('writeContained — close failures', () => {
|
|
113
|
+
it('REFUSES when closeSync throws, even though the write itself succeeded', () => {
|
|
114
|
+
closeError = Object.assign(new Error('disk quota exceeded'), { code: 'EDQUOT' });
|
|
115
|
+
const dest = join(destRoot, 'rg.md');
|
|
116
|
+
const w = writeContained(dest, destRoot, 'content');
|
|
117
|
+
expect(w.ok).toBe(false);
|
|
118
|
+
if (w.ok)
|
|
119
|
+
return;
|
|
120
|
+
expect(w.detail).toContain('could not close');
|
|
121
|
+
expect(w.detail).toContain('disk quota exceeded');
|
|
122
|
+
});
|
|
123
|
+
it('reports the WRITE failure in preference to the close failure', () => {
|
|
124
|
+
// Both fail; the write error is the more informative one.
|
|
125
|
+
chunkSize = 0;
|
|
126
|
+
closeError = new Error('close also failed');
|
|
127
|
+
const dest = join(destRoot, 'rg.md');
|
|
128
|
+
const w = writeContained(dest, destRoot, 'content');
|
|
129
|
+
expect(w.ok).toBe(false);
|
|
130
|
+
if (w.ok)
|
|
131
|
+
return;
|
|
132
|
+
expect(w.detail).toContain('short write');
|
|
133
|
+
});
|
|
134
|
+
it('succeeds normally when neither fails', () => {
|
|
135
|
+
const dest = join(destRoot, 'rg.md');
|
|
136
|
+
const w = writeContained(dest, destRoot, 'content');
|
|
137
|
+
expect(w.ok).toBe(true);
|
|
138
|
+
expect(readFileSync(dest, 'utf-8')).toBe('content');
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
//# sourceMappingURL=provision-write-integrity.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provision-write-integrity.test.js","sourceRoot":"","sources":["../../src/__tests__/provision-write-integrity.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,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ferLevel('Team: demo', 'out')).toBe('info');
|
|
59
|
-
expect(inferLevel('[mx-agent]
|
|
59
|
+
expect(inferLevel('[mx-agent] plain stderr line with no glyph', 'err')).toBe('warning');
|
|
60
60
|
expect(inferLevel('Error: not found', 'error-console')).toBe('error');
|
|
61
61
|
});
|
|
62
62
|
});
|
|
@@ -231,13 +231,13 @@ describe('console-capture tee', () => {
|
|
|
231
231
|
console.log('\x1b[33m ⚠ heads up\x1b[39m');
|
|
232
232
|
console.log(' '); // whitespace-only — must NOT be recorded
|
|
233
233
|
console.error('\x1b[31mError: nope\x1b[39m');
|
|
234
|
-
process.stderr.write('[mx-agent]
|
|
234
|
+
process.stderr.write('[mx-agent] plain stderr line with no glyph\n');
|
|
235
235
|
startupReport.removeConsoleCapture();
|
|
236
236
|
const entries = startupReport._entries();
|
|
237
237
|
const levels = entries.map((e) => e.level);
|
|
238
238
|
expect(levels).toEqual(['success', 'info', 'warning', 'error', 'warning']);
|
|
239
239
|
expect(entries[0].message).toBe(' ✓ Deployed');
|
|
240
|
-
expect(entries.find((e) => e.message.includes('
|
|
240
|
+
expect(entries.find((e) => e.message.includes('plain stderr line'))).toBeTruthy();
|
|
241
241
|
// Output still went out: 4 console.log calls (incl. the whitespace one).
|
|
242
242
|
expect(logSpy).toHaveBeenCalledTimes(4);
|
|
243
243
|
expect(errSpy).toHaveBeenCalledTimes(1);
|