@memnexus-ai/mx-agent-cli 0.1.296-next.1 → 0.1.296-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/coordination-brief-pin.test.js +6 -2
- package/dist/__tests__/coordination-brief-pin.test.js.map +1 -1
- package/dist/__tests__/coordination-credential-endpoint.test.js +9 -7
- package/dist/__tests__/coordination-credential-endpoint.test.js.map +1 -1
- package/dist/__tests__/coordination-expected-team.test.d.ts +19 -0
- package/dist/__tests__/coordination-expected-team.test.d.ts.map +1 -0
- package/dist/__tests__/coordination-expected-team.test.js +423 -0
- package/dist/__tests__/coordination-expected-team.test.js.map +1 -0
- package/dist/__tests__/coordination-plain-shell-commands.test.js +494 -26
- package/dist/__tests__/coordination-plain-shell-commands.test.js.map +1 -1
- package/dist/__tests__/memory-log-result.test.js +36 -0
- package/dist/__tests__/memory-log-result.test.js.map +1 -1
- package/dist/__tests__/runtime-codex-adapter.test.js +33 -1
- package/dist/__tests__/runtime-codex-adapter.test.js.map +1 -1
- package/dist/__tests__/start-runtime-wiring.test.js +150 -2
- package/dist/__tests__/start-runtime-wiring.test.js.map +1 -1
- package/dist/__tests__/team-name-propagation.test.js +63 -0
- package/dist/__tests__/team-name-propagation.test.js.map +1 -1
- package/dist/__tests__/tracked-instruction-files.test.d.ts +21 -0
- package/dist/__tests__/tracked-instruction-files.test.d.ts.map +1 -0
- package/dist/__tests__/tracked-instruction-files.test.js +489 -0
- package/dist/__tests__/tracked-instruction-files.test.js.map +1 -0
- package/dist/__tests__/verify-hooks-check-all.test.js +12 -2
- package/dist/__tests__/verify-hooks-check-all.test.js.map +1 -1
- package/dist/agent-config/hooks/coordination-brief.sh +30 -6
- package/dist/commands/coordination.d.ts +36 -1
- package/dist/commands/coordination.d.ts.map +1 -1
- package/dist/commands/coordination.js +183 -10
- package/dist/commands/coordination.js.map +1 -1
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +3 -1
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/start.d.ts +28 -0
- package/dist/commands/start.d.ts.map +1 -1
- package/dist/commands/start.js +68 -4
- package/dist/commands/start.js.map +1 -1
- package/dist/lib/agent-session.d.ts.map +1 -1
- package/dist/lib/agent-session.js +4 -0
- package/dist/lib/agent-session.js.map +1 -1
- package/dist/lib/claude.d.ts +25 -1
- package/dist/lib/claude.d.ts.map +1 -1
- package/dist/lib/claude.js +120 -25
- package/dist/lib/claude.js.map +1 -1
- package/dist/lib/coordination-worktree.d.ts +0 -26
- package/dist/lib/coordination-worktree.d.ts.map +1 -1
- package/dist/lib/coordination-worktree.js +61 -5
- package/dist/lib/coordination-worktree.js.map +1 -1
- package/dist/lib/instruction-files.d.ts +30 -0
- package/dist/lib/instruction-files.d.ts.map +1 -0
- package/dist/lib/instruction-files.js +45 -0
- package/dist/lib/instruction-files.js.map +1 -0
- package/dist/lib/memory.d.ts.map +1 -1
- package/dist/lib/memory.js +15 -3
- package/dist/lib/memory.js.map +1 -1
- package/dist/lib/runtime/codex-adapter.d.ts.map +1 -1
- package/dist/lib/runtime/codex-adapter.js +4 -0
- package/dist/lib/runtime/codex-adapter.js.map +1 -1
- package/package.json +1 -1
|
@@ -1075,7 +1075,34 @@ describe('red-team finding 1: a cwd-located marker that is tracked in git names
|
|
|
1075
1075
|
expect(defaultTrackedCoordinationFiles('/p', () => { throw new Error('timed out'); })).toBeUndefined();
|
|
1076
1076
|
expect(defaultTrackedCoordinationFiles('/p', () => '')).toEqual([]);
|
|
1077
1077
|
});
|
|
1078
|
-
|
|
1078
|
+
// #548 flipped this test on purpose. Until #548 it was named "the tracked marker
|
|
1079
|
+
// is used exactly as at 082c7d8 (this PR does not fix sessions, #527 does)" and
|
|
1080
|
+
// pinned that a session acted as `product`. A session `mx-agent start` launches
|
|
1081
|
+
// now carries MX_COORD_EXPECT_TEAM, and every coordination command refuses the
|
|
1082
|
+
// mismatched marker before any credential. The case without the variable is
|
|
1083
|
+
// kept below it, unchanged, because #548 criterion 7b requires exactly that.
|
|
1084
|
+
it('CLAUDE_WORKTREE_PATH and MX_COORD_EXPECT_TEAM set: the tracked marker is refused by escalate and status, and nothing is sent (#548 fixes sessions)', async () => {
|
|
1085
|
+
const { main, worktrees } = makeTrackedMarkerProject();
|
|
1086
|
+
const wt = worktrees[0];
|
|
1087
|
+
writeFileSync(join(wt, '.mx-code-context.json'), JSON.stringify({ team: 'personal-coach' }));
|
|
1088
|
+
process.env.MX_PROJECT_ROOT = main;
|
|
1089
|
+
process.env.CLAUDE_WORKTREE_PATH = wt;
|
|
1090
|
+
process.env.MX_COORD_EXPECT_TEAM = 'personal-coach';
|
|
1091
|
+
plainShellAt(wt);
|
|
1092
|
+
// readTeamMarker itself is unchanged for every caller (#548 criterion 9).
|
|
1093
|
+
expect(readTeamMarker({ root: wt, source: 'CLAUDE_WORKTREE_PATH' })).toEqual({ kind: 'ok', line: 'product' });
|
|
1094
|
+
const enqueue = vi.fn(async () => ({ messageId: 'never', duplicate: false }));
|
|
1095
|
+
await expect(runEscalate({ to: 'engineering', priority: 'p2', body: 'hello' }, { client: recordingClient(enqueue) }))
|
|
1096
|
+
.rejects.toThrow('process.exit(1)');
|
|
1097
|
+
expect(enqueue).not.toHaveBeenCalled();
|
|
1098
|
+
await expect(runStatus({ fetch: okFetch(), registration: { client: recordingClient(enqueue), ...noOffline } }))
|
|
1099
|
+
.rejects.toThrow('process.exit(1)');
|
|
1100
|
+
expect(logs.join('\n')).not.toMatch(/Team: +product/);
|
|
1101
|
+
const out = errs.join('\n');
|
|
1102
|
+
expect(out).toContain(`The .mx-coordination-team marker at ${join(wt, '.mx-coordination-team')} names team "product", but this session was started as team "personal-coach"`);
|
|
1103
|
+
expect(cacheFilesIn(wt)).toEqual([]);
|
|
1104
|
+
});
|
|
1105
|
+
it('CLAUDE_WORKTREE_PATH set and MX_COORD_EXPECT_TEAM absent: the tracked marker is used exactly as at 082c7d8 (#548 criterion 7b)', async () => {
|
|
1079
1106
|
const { main, worktrees } = makeTrackedMarkerProject();
|
|
1080
1107
|
const wt = worktrees[0];
|
|
1081
1108
|
writeFileSync(join(wt, '.mx-code-context.json'), JSON.stringify({ team: 'personal-coach' }));
|
|
@@ -1192,26 +1219,133 @@ describe.skipIf(typeof process.getuid !== 'function')('round 4 small items', ()
|
|
|
1192
1219
|
});
|
|
1193
1220
|
});
|
|
1194
1221
|
// ── Fix round 5: reviews at 2b8c8fd ─────────────────────────────────────
|
|
1222
|
+
/** Every backticked `git ...` span the remedy prints, in order. */
|
|
1223
|
+
const printedGitCommands = () => TRACKED_REMEDY.flatMap((line) => [...line.matchAll(/`(git [^`]+)`/g)].map((m) => m[1]));
|
|
1224
|
+
/** The check of step 2a: lists what is staged other than the marker and the cache files. */
|
|
1225
|
+
const isCheckStep = (command) => command.startsWith('git diff --cached --name-status');
|
|
1226
|
+
/** The check of step 1a: lists the marker and the cache files still in the index. */
|
|
1227
|
+
const isRemovalCheckStep = (command) => command.startsWith('git ls-files');
|
|
1228
|
+
/** The end check of step 2e: reports each of the two files as ignored or not. */
|
|
1229
|
+
const isEndCheckStep = (command) => command.startsWith('git status');
|
|
1230
|
+
/** The printed commands up to and including the check of step 2a. */
|
|
1231
|
+
const throughCheck = () => printedGitCommands().slice(0, printedGitCommands().findIndex(isCheckStep) + 1);
|
|
1232
|
+
/** An identity for the printed `git commit`, which runs through a shell with no `-c user.*`. */
|
|
1233
|
+
const PRINTED_COMMIT_ENV = { GIT_AUTHOR_NAME: 't', GIT_AUTHOR_EMAIL: 't@e.com', GIT_COMMITTER_NAME: 't', GIT_COMMITTER_EMAIL: 't@e.com' };
|
|
1195
1234
|
/**
|
|
1196
|
-
*
|
|
1197
|
-
*
|
|
1235
|
+
* The environment the printed commands run in: no inherited GIT_* variable (a
|
|
1236
|
+
* pathspec switch such as GIT_LITERAL_PATHSPECS would change what every printed
|
|
1237
|
+
* pathspec means) and no coordination credential, as `runGit` strips them
|
|
1238
|
+
* (security review of PR #561, INFO). Then the commit identity.
|
|
1198
1239
|
*/
|
|
1199
|
-
function
|
|
1200
|
-
const
|
|
1201
|
-
for (const
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
throw new Error(`${command}: ${r.stderr}`);
|
|
1240
|
+
function printedCommandEnv() {
|
|
1241
|
+
const env = {};
|
|
1242
|
+
for (const [k, v] of Object.entries(process.env)) {
|
|
1243
|
+
if (!k.startsWith('GIT_') && !GIT_CHILD_STRIP.includes(k))
|
|
1244
|
+
env[k] = v;
|
|
1205
1245
|
}
|
|
1206
|
-
return
|
|
1246
|
+
return { ...env, ...PRINTED_COMMIT_ENV };
|
|
1207
1247
|
}
|
|
1208
|
-
/**
|
|
1209
|
-
|
|
1210
|
-
|
|
1248
|
+
/** The printed `git add` of step 2b, whatever pathspec form it takes. */
|
|
1249
|
+
const isAddStep = (command) => command.startsWith('git add ') && command.includes('.gitignore');
|
|
1250
|
+
/** The two ignore rules step 2 names: its backticked spans that are not commands. */
|
|
1251
|
+
function printedIgnoreRules() {
|
|
1252
|
+
const line = TRACKED_REMEDY.find((l) => l.includes('Add two lines'));
|
|
1253
|
+
if (line === undefined)
|
|
1254
|
+
throw new Error('the remedy names no ignore rules');
|
|
1255
|
+
const rules = [...line.matchAll(/`([^`]+)`/g)].map((m) => m[1]).filter((span) => !span.startsWith('git '));
|
|
1211
1256
|
expect(rules).toEqual(['.mx-coordination-team', '.mx-coordination-token--*']);
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1257
|
+
return rules;
|
|
1258
|
+
}
|
|
1259
|
+
/**
|
|
1260
|
+
* The manual edit of step 2: each rule as a line of .gitignore, leaving out a
|
|
1261
|
+
* line it already holds, plus any exact case-variant name step 1 removed
|
|
1262
|
+
* (`extra`), as step 2b says.
|
|
1263
|
+
*/
|
|
1264
|
+
function addPrintedIgnoreRules(dir, extra = []) {
|
|
1265
|
+
const path = join(dir, '.gitignore');
|
|
1266
|
+
const before = existsSync(path) ? readFileSync(path, 'utf-8') : '';
|
|
1267
|
+
const held = new Set(before.split('\n'));
|
|
1268
|
+
const added = [...printedIgnoreRules(), ...extra].filter((rule) => !held.has(rule));
|
|
1269
|
+
const sep = before === '' || before.endsWith('\n') ? '' : '\n';
|
|
1270
|
+
writeFileSync(path, `${before}${sep}${added.map((rule) => `${rule}\n`).join('')}`);
|
|
1271
|
+
}
|
|
1272
|
+
/**
|
|
1273
|
+
* Follow the remedy in `dir` as an operator who reads it literally does: run
|
|
1274
|
+
* every git command it prints, exactly as printed, through a shell, and make
|
|
1275
|
+
* the .gitignore edit of step 2 by hand just before the printed
|
|
1276
|
+
* `git add` of step 2b.
|
|
1277
|
+
*
|
|
1278
|
+
* The checks of steps 1a and 2a exit 0 whatever they print, so this function
|
|
1279
|
+
* carries the text's stop rule: when either prints any line, it stops there
|
|
1280
|
+
* and returns that output, and nothing after it runs (#540). The end check of
|
|
1281
|
+
* step 2e is returned in `output` for the test to read.
|
|
1282
|
+
*
|
|
1283
|
+
* `skipRemoval` does not run the printed `git rm` of step 1. It stands in for a
|
|
1284
|
+
* step 1 that matched nothing, on another git version or for an odd name
|
|
1285
|
+
* (red-team, Step 6 on PR #561). `extraIgnore` is the case-variant name step 2b
|
|
1286
|
+
* tells the operator to add. `beforeCommit` runs just before the printed
|
|
1287
|
+
* `git commit`, for a fixture that changes the index there.
|
|
1288
|
+
*
|
|
1289
|
+
* The step 1a listing is printed twice, at 1a and again at the start of 2e.
|
|
1290
|
+
* Both stop the steps when they print a line; `output` holds the later run.
|
|
1291
|
+
*
|
|
1292
|
+
* Every other command must exit 0, except the printed `git commit` when
|
|
1293
|
+
* `nothingToCommit` is set: the text says a non-zero exit is expected there
|
|
1294
|
+
* when .gitignore already held both lines and step 1 removed nothing.
|
|
1295
|
+
*
|
|
1296
|
+
* `from: 'check'` resumes at the check, which is what the text says to do after
|
|
1297
|
+
* the operator commits or unstages the files it printed.
|
|
1298
|
+
*
|
|
1299
|
+
* `cwd` is where the operator pastes the commands, `dir` or any directory
|
|
1300
|
+
* inside it: the refusal fires from any of them (security review of PR #561).
|
|
1301
|
+
* The .gitignore edit is always made in `dir`, the worktree's top directory,
|
|
1302
|
+
* as step 2b says.
|
|
1303
|
+
*
|
|
1304
|
+
* Criterion 8 of #540 needs the regression test to fail on the text at
|
|
1305
|
+
* 93f738a, whose step 2 printed no command and said in prose to "commit both
|
|
1306
|
+
* changes". When the remedy prints no `git commit`, the operator follows that
|
|
1307
|
+
* prose with a plain `git commit`, which commits everything staged. The current
|
|
1308
|
+
* text always prints a `git commit` (the span list test pins it), so that
|
|
1309
|
+
* branch models only the text #540 replaced.
|
|
1310
|
+
*/
|
|
1311
|
+
function followPrintedRemedy(dir, opts = {}) {
|
|
1312
|
+
const commands = printedGitCommands();
|
|
1313
|
+
const start = opts.from === 'check' ? commands.findIndex(isCheckStep) : 0;
|
|
1314
|
+
expect(start).toBeGreaterThanOrEqual(0);
|
|
1315
|
+
const run = { ran: [], output: {} };
|
|
1316
|
+
let edited = false;
|
|
1317
|
+
for (const command of commands.slice(start)) {
|
|
1318
|
+
if (opts.skipRemoval && command.startsWith('git rm '))
|
|
1319
|
+
continue;
|
|
1320
|
+
if (isAddStep(command)) {
|
|
1321
|
+
addPrintedIgnoreRules(dir, opts.extraIgnore);
|
|
1322
|
+
edited = true;
|
|
1323
|
+
}
|
|
1324
|
+
if (command.startsWith('git commit'))
|
|
1325
|
+
opts.beforeCommit?.();
|
|
1326
|
+
const r = spawnSync('bash', ['-c', command], { cwd: opts.cwd ?? dir, encoding: 'utf-8', env: printedCommandEnv() });
|
|
1327
|
+
run.ran.push(command);
|
|
1328
|
+
run.output[command] = r.stdout;
|
|
1329
|
+
if (command.startsWith('git commit')) {
|
|
1330
|
+
run.commitStatus = r.status ?? -1;
|
|
1331
|
+
if (opts.nothingToCommit && r.status !== 0)
|
|
1332
|
+
continue;
|
|
1333
|
+
}
|
|
1334
|
+
if (r.status !== 0)
|
|
1335
|
+
throw new Error(`${command}: ${r.stderr}`);
|
|
1336
|
+
if ((isCheckStep(command) || isRemovalCheckStep(command)) && r.stdout.trim() !== '') {
|
|
1337
|
+
run.stopped = r.stdout;
|
|
1338
|
+
run.stoppedAt = command;
|
|
1339
|
+
return run;
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
if (!commands.some((c) => c.startsWith('git commit'))) {
|
|
1343
|
+
if (!edited)
|
|
1344
|
+
addPrintedIgnoreRules(dir);
|
|
1345
|
+
git(dir, 'add', '.gitignore');
|
|
1346
|
+
git(dir, 'commit', '-q', '-m', 'stop tracking the coordination marker');
|
|
1347
|
+
}
|
|
1348
|
+
return run;
|
|
1215
1349
|
}
|
|
1216
1350
|
/** Steps 3 and 4: delete the leftover file, then what `mx-agent start <team>` does to the marker (start.ts step 5a). */
|
|
1217
1351
|
function deleteLeftoverThenStartWritesMarker(dir, team) {
|
|
@@ -1223,18 +1357,51 @@ describe('QA M2, red-team A and C: the tracked-file remedy works when followed e
|
|
|
1223
1357
|
const tokenIn = (main, wt, fetchCredential) => resolveCoordinationToken({ env: {}, ...credentialDeps(fetchCredential), locate: { cwd: wt, projectRoot: () => main } });
|
|
1224
1358
|
it('the remedy names both files, both ignore rules, the per-branch scope, and what start does', () => {
|
|
1225
1359
|
const text = TRACKED_REMEDY.join('\n');
|
|
1226
|
-
expect(text).toContain("`git rm --cached -f --ignore-unmatch -- .mx-coordination-
|
|
1360
|
+
expect(text).toContain("`git rm --cached -f --ignore-unmatch -- ':(top,icase,glob).mx-coordination-tea[m]' ':(top,icase,glob).mx-coordination-token--*'`");
|
|
1227
1361
|
expect(text).toContain('`.mx-coordination-team` and `.mx-coordination-token--*`');
|
|
1228
1362
|
expect(text).toContain('Git tracks files per branch and every worktree has its own branch');
|
|
1229
1363
|
expect(text).toContain('Every other worktree stays refused until its own branch stops tracking the files');
|
|
1230
|
-
expect(text).toContain('
|
|
1364
|
+
expect(text).toContain('the branch that holds the commit from step 2d');
|
|
1365
|
+
expect(text).toContain("3. On this first pass, before step 4, delete the .mx-coordination-team file left in that worktree's top directory.");
|
|
1366
|
+
expect(text).toContain('If you repeat these steps after step 4, skip this step: the marker is then the one step 4 wrote for this team.');
|
|
1231
1367
|
expect(text).toContain('for a worktree directory named <team>-<date>, the part before the date');
|
|
1232
1368
|
expect(text).toContain('then opens a session');
|
|
1369
|
+
// #540: check, stage, show, commit, and what each result means.
|
|
1370
|
+
expect(text).toContain('If it prints any line, stop: a commit now would include those files.');
|
|
1371
|
+
expect(text).toContain('Nothing has been committed yet. The removals from step 1 stay staged and the files stay on disk, so a commit you make now records those removals too. After you have committed or unstaged the printed files yourself, run step 2a again.');
|
|
1372
|
+
expect(text).toContain('Steps 1 and 2a match the two names in any letter case, the way the check that refused this worktree does, so step 1 has already removed a marker or cache file whose name differs only in case, and step 2a does not print one.');
|
|
1373
|
+
expect(text).toContain('If .gitignore already held every line it prints nothing, which is expected, and step 2d then reports nothing to commit unless step 1 removed a file.');
|
|
1374
|
+
// QA W2 and W3 at 5f31405: the count includes exact case-variant names and, on a repeat, the operator's own correction.
|
|
1375
|
+
expect(text).toContain('2 added, plus one for each exact name you added in step 2b (fewer if .gitignore already held a line), and 0 deleted.');
|
|
1376
|
+
expect(text).toContain('On a repeat after you corrected .gitignore in step 2e, it also counts your own correction, for example 0 and 1 when you removed a negation line, which is expected.');
|
|
1377
|
+
expect(text).toContain("to the .gitignore in the worktree's top directory");
|
|
1378
|
+
expect(text).toContain('from any directory inside it');
|
|
1379
|
+
// Red-team, Step 6 on PR #561: a positive check after step 1, an end check, a failed commit, case-variant names.
|
|
1380
|
+
expect(text).toContain('It must print nothing. If it prints a line, stop: step 1 did not remove that file from the index, and a commit would record it. Nothing has been committed.');
|
|
1381
|
+
expect(text).toContain('in five parts');
|
|
1382
|
+
expect(text).toContain('Every line it prints must start with !!, which means git ignores that file.');
|
|
1383
|
+
expect(text).toContain('for example because a later negation line such as !.mx-* includes it again');
|
|
1384
|
+
// Security Should Fix and QA W1 at 5f31405: 2e repeats the listing, and says what each status output means.
|
|
1385
|
+
expect(text).not.toContain('Any other line means git still tracks the file');
|
|
1386
|
+
expect(text).toContain("` again. It must print nothing. A line means git still tracks that file: start again at step 1. Then run `git status");
|
|
1387
|
+
expect(text).toContain('A line with any other status means git still tracks that file and it has changes: start again at step 1.');
|
|
1388
|
+
expect(text).toContain('Empty output means neither file is on disk, which is fine once the listing before it printed nothing.');
|
|
1389
|
+
expect(text).toContain('If the commit fails for another reason, for example a pre-commit hook or commit signing, nothing was committed and everything stays staged: fix the cause and run step 2d again.');
|
|
1390
|
+
expect(text).toContain('If step 1 removed a file whose name differs from these only in letter case, add that exact name as a line too; on a case-insensitive file system this is unnecessary but harmless.');
|
|
1391
|
+
expect(text).toContain('It should print the lines added, the lines deleted and .gitignore: 2 added');
|
|
1392
|
+
expect(text).toContain('there is nothing to commit: git says so and exits non-zero, which is expected here');
|
|
1233
1393
|
// Constants only: nothing from disk can be inside a printed command.
|
|
1234
1394
|
expect([...text.matchAll(/`([^`]+)`/g)].map((m) => m[1])).toEqual([
|
|
1235
|
-
"git rm --cached -f --ignore-unmatch -- .mx-coordination-
|
|
1395
|
+
"git rm --cached -f --ignore-unmatch -- ':(top,icase,glob).mx-coordination-tea[m]' ':(top,icase,glob).mx-coordination-token--*'",
|
|
1396
|
+
"git ls-files -- ':(top,icase,glob).mx-coordination-tea[m]' ':(top,icase,glob).mx-coordination-token--*'",
|
|
1397
|
+
"git diff --cached --name-status -- ':(top)' ':(top,exclude,icase,glob).mx-coordination-tea[m]' ':(top,exclude,icase,glob).mx-coordination-token--*'",
|
|
1236
1398
|
'.mx-coordination-team',
|
|
1237
1399
|
'.mx-coordination-token--*',
|
|
1400
|
+
"git add ':(top).gitignore'",
|
|
1401
|
+
"git diff --cached --numstat -- ':(top).gitignore'",
|
|
1402
|
+
"git commit -m 'Stop tracking the coordination marker and token cache files'",
|
|
1403
|
+
"git ls-files -- ':(top,icase,glob).mx-coordination-tea[m]' ':(top,icase,glob).mx-coordination-token--*'",
|
|
1404
|
+
"git status --porcelain --ignored=matching --untracked-files=all -- ':(top,icase,glob).mx-coordination-tea[m]' ':(top,icase,glob).mx-coordination-token--*'",
|
|
1238
1405
|
'mx-agent start <team>',
|
|
1239
1406
|
'start',
|
|
1240
1407
|
]);
|
|
@@ -1244,8 +1411,10 @@ describe('QA M2, red-team A and C: the tracked-file remedy works when followed e
|
|
|
1244
1411
|
const [first, second] = worktrees;
|
|
1245
1412
|
expect((await tokenIn(main, first, issued())).status).toBe('misconfigured');
|
|
1246
1413
|
// Steps 1 to 4, in the first worktree, as printed.
|
|
1247
|
-
|
|
1248
|
-
|
|
1414
|
+
const run = followPrintedRemedy(first);
|
|
1415
|
+
expect(run.stopped).toBeUndefined();
|
|
1416
|
+
expect(run.ran).toEqual(printedGitCommands());
|
|
1417
|
+
expect(run.ran).toHaveLength(8);
|
|
1249
1418
|
deleteLeftoverThenStartWritesMarker(first, 'personal-coach');
|
|
1250
1419
|
const fetchCredential = issued();
|
|
1251
1420
|
const fixed = await tokenIn(main, first, fetchCredential);
|
|
@@ -1265,8 +1434,7 @@ describe('QA M2, red-team A and C: the tracked-file remedy works when followed e
|
|
|
1265
1434
|
const { main, worktrees } = makeTrackedMarkerProject();
|
|
1266
1435
|
const [first] = worktrees;
|
|
1267
1436
|
// What QA did at 2b8c8fd: steps 1 and 2 on the base branch, steps 3 and 4 in the worktree.
|
|
1268
|
-
|
|
1269
|
-
addPrintedIgnoreRulesAndCommit(main);
|
|
1437
|
+
expect(followPrintedRemedy(main).stopped).toBeUndefined();
|
|
1270
1438
|
deleteLeftoverThenStartWritesMarker(first, 'personal-coach');
|
|
1271
1439
|
const fetchCredential = issued();
|
|
1272
1440
|
const res = await tokenIn(main, first, fetchCredential);
|
|
@@ -1276,8 +1444,7 @@ describe('QA M2, red-team A and C: the tracked-file remedy works when followed e
|
|
|
1276
1444
|
it('the other route the remedy names: merging the branch that holds the commit, then steps 3 and 4', async () => {
|
|
1277
1445
|
const { main, worktrees } = makeTrackedMarkerProject();
|
|
1278
1446
|
const [first, second] = worktrees;
|
|
1279
|
-
|
|
1280
|
-
addPrintedIgnoreRulesAndCommit(first);
|
|
1447
|
+
expect(followPrintedRemedy(first).stopped).toBeUndefined();
|
|
1281
1448
|
git(second, 'merge', '-q', '--no-edit', 'worktree/personal-coach-20260927');
|
|
1282
1449
|
expect(defaultTrackedCoordinationFiles(second)).toEqual([]);
|
|
1283
1450
|
deleteLeftoverThenStartWritesMarker(second, 'engineering');
|
|
@@ -1300,7 +1467,7 @@ describe('QA M2, red-team A and C: the tracked-file remedy works when followed e
|
|
|
1300
1467
|
expect(refused.detail).toContain('is tracked or staged in git on the branch that worktree has checked out');
|
|
1301
1468
|
expect(refused.detail).not.toContain('life-planner--alpha');
|
|
1302
1469
|
expect(refusedFetch).not.toHaveBeenCalled();
|
|
1303
|
-
|
|
1470
|
+
expect(followPrintedRemedy(worktree).stopped).toBeUndefined();
|
|
1304
1471
|
expect(existsSync(cache)).toBe(true);
|
|
1305
1472
|
const fetchCredential = issued();
|
|
1306
1473
|
const res = await tokenIn(main, worktree, fetchCredential);
|
|
@@ -1309,6 +1476,307 @@ describe('QA M2, red-team A and C: the tracked-file remedy works when followed e
|
|
|
1309
1476
|
expect(fetchCredential).not.toHaveBeenCalled();
|
|
1310
1477
|
});
|
|
1311
1478
|
});
|
|
1479
|
+
// ── #540: step 2 commits only what the remedy means to commit ───────────
|
|
1480
|
+
const MARKER = '.mx-coordination-team';
|
|
1481
|
+
const CACHE = '.mx-coordination-token--x--y';
|
|
1482
|
+
const REMEDY_COMMIT_MESSAGE = 'Stop tracking the coordination marker and token cache files';
|
|
1483
|
+
function gitOut(cwd, ...a) {
|
|
1484
|
+
const r = spawnSync('git', ['-c', 'user.email=t@e.com', '-c', 'user.name=t', ...a], { cwd, encoding: 'utf-8' });
|
|
1485
|
+
if (r.status !== 0)
|
|
1486
|
+
throw new Error(r.stderr);
|
|
1487
|
+
return r.stdout;
|
|
1488
|
+
}
|
|
1489
|
+
/**
|
|
1490
|
+
* The fixture #540's success criteria name. A linked worktree whose .gitignore
|
|
1491
|
+
* holds neither rule, with the marker and the cache file `.mx-coordination-token--x--y`
|
|
1492
|
+
* both staged.
|
|
1493
|
+
*
|
|
1494
|
+
* - 'tracked': HEAD holds the marker and the cache file (#527's layout), and
|
|
1495
|
+
* the worktree has staged new contents for both.
|
|
1496
|
+
* - 'staged-only': HEAD holds neither, and both are staged as new files, as
|
|
1497
|
+
* `mx-agent start` staged them with `git add -A` in Life Planner (1b).
|
|
1498
|
+
*/
|
|
1499
|
+
function makeRemedyFixture(variant) {
|
|
1500
|
+
const main = join(base, 'life-planner');
|
|
1501
|
+
mkdirSync(main, { recursive: true });
|
|
1502
|
+
git(main, 'init', '-q', '-b', 'main');
|
|
1503
|
+
writeFileSync(join(main, 'mx-agent.config.json'), JSON.stringify({ projectSlug: 'life-planner', coordinationMode: 'queue' }));
|
|
1504
|
+
writeFileSync(join(main, '.gitignore'), '.worktrees/\n');
|
|
1505
|
+
// A subdirectory with its own tracked .gitignore, where an operator may paste the steps.
|
|
1506
|
+
mkdirSync(join(main, 'sub'));
|
|
1507
|
+
writeFileSync(join(main, 'sub', '.gitignore'), '*.log\n');
|
|
1508
|
+
if (variant === 'tracked') {
|
|
1509
|
+
writeFileSync(join(main, MARKER), 'product\n');
|
|
1510
|
+
writeFileSync(join(main, CACHE), 'committed-token-not-real\n', { mode: 0o600 });
|
|
1511
|
+
}
|
|
1512
|
+
git(main, 'add', '-A');
|
|
1513
|
+
git(main, 'commit', '-q', '-m', 'init');
|
|
1514
|
+
const wt = join(main, '.worktrees', 'personal-coach-20260927');
|
|
1515
|
+
git(main, 'worktree', 'add', '-q', '-b', 'worktree/personal-coach-20260927', wt);
|
|
1516
|
+
chmodSync(wt, 0o755);
|
|
1517
|
+
writeFileSync(join(wt, MARKER), 'personal-coach\n');
|
|
1518
|
+
writeFileSync(join(wt, CACHE), 'staged-token-not-real\n', { mode: 0o600 });
|
|
1519
|
+
git(wt, 'add', '--', MARKER, CACHE);
|
|
1520
|
+
expect(gitOut(wt, 'diff', '--cached', '--name-status')).toBe(variant === 'tracked' ? `M\t${MARKER}\nM\t${CACHE}\n` : `A\t${MARKER}\nA\t${CACHE}\n`);
|
|
1521
|
+
return wt;
|
|
1522
|
+
}
|
|
1523
|
+
const headOf = (dir) => gitOut(dir, 'rev-parse', 'HEAD').trim();
|
|
1524
|
+
const stagedIn = (dir) => gitOut(dir, 'diff', '--cached', '--name-status');
|
|
1525
|
+
const showHead = (dir) => gitOut(dir, 'show', '--name-status', '--format=', 'HEAD');
|
|
1526
|
+
const NUMSTAT = "git diff --cached --numstat -- ':(top).gitignore'";
|
|
1527
|
+
const END_CHECK = "git status --porcelain --ignored=matching --untracked-files=all -- ':(top,icase,glob).mx-coordination-tea[m]' ':(top,icase,glob).mx-coordination-token--*'";
|
|
1528
|
+
const BOTH_IGNORED = `!! ${MARKER}\n!! ${CACHE}\n`;
|
|
1529
|
+
/** Criterion 3: both files untracked, ignored and still on disk with the contents they had. */
|
|
1530
|
+
function expectUntrackedIgnoredOnDisk(wt) {
|
|
1531
|
+
expect(gitOut(wt, 'ls-files', '--', MARKER, CACHE)).toBe('');
|
|
1532
|
+
expect(gitOut(wt, 'check-ignore', '--', MARKER, CACHE)).toBe(`${MARKER}\n${CACHE}\n`);
|
|
1533
|
+
expect(readFileSync(join(wt, MARKER), 'utf-8')).toBe('personal-coach\n');
|
|
1534
|
+
expect(readFileSync(join(wt, CACHE), 'utf-8')).toBe('staged-token-not-real\n');
|
|
1535
|
+
}
|
|
1536
|
+
describe('#540: the printed step 2 commits only the ignore rules and the removal of the two files', () => {
|
|
1537
|
+
it('criterion 1 (regression, criterion 8): a staged notes.txt is printed by the check and the steps stop with nothing committed', () => {
|
|
1538
|
+
const wt = makeRemedyFixture('tracked');
|
|
1539
|
+
writeFileSync(join(wt, 'notes.txt'), 'the operator\'s own work\n');
|
|
1540
|
+
git(wt, 'add', 'notes.txt');
|
|
1541
|
+
const before = headOf(wt);
|
|
1542
|
+
const run = followPrintedRemedy(wt);
|
|
1543
|
+
// Nothing was committed, and notes.txt is still staged, not discarded.
|
|
1544
|
+
expect(headOf(wt)).toBe(before);
|
|
1545
|
+
expect(stagedIn(wt)).toContain('A\tnotes.txt\n');
|
|
1546
|
+
expect(readFileSync(join(wt, 'notes.txt'), 'utf-8')).toBe('the operator\'s own work\n');
|
|
1547
|
+
// The check printed notes.txt, and only notes.txt: the marker and the cache are excluded.
|
|
1548
|
+
expect(run.stopped).toBe('A\tnotes.txt\n');
|
|
1549
|
+
expect(run.ran).toEqual(throughCheck());
|
|
1550
|
+
// The steps stopped before the .gitignore edit.
|
|
1551
|
+
expect(readFileSync(join(wt, '.gitignore'), 'utf-8')).toBe('.worktrees/\n');
|
|
1552
|
+
});
|
|
1553
|
+
it('criterion 1a: once the operator unstages notes.txt, the check prints nothing and the commit is exactly .gitignore and the two removals', () => {
|
|
1554
|
+
const wt = makeRemedyFixture('tracked');
|
|
1555
|
+
writeFileSync(join(wt, 'notes.txt'), 'the operator\'s own work\n');
|
|
1556
|
+
git(wt, 'add', 'notes.txt');
|
|
1557
|
+
const before = headOf(wt);
|
|
1558
|
+
expect(followPrintedRemedy(wt).stopped).toBe('A\tnotes.txt\n');
|
|
1559
|
+
// The operator unstages it, which the text leaves to them, then runs the check again.
|
|
1560
|
+
git(wt, 'restore', '--staged', 'notes.txt');
|
|
1561
|
+
const run = followPrintedRemedy(wt, { from: 'check' });
|
|
1562
|
+
expect(run.stopped).toBeUndefined();
|
|
1563
|
+
expect(run.output[printedGitCommands().find(isCheckStep)]).toBe('');
|
|
1564
|
+
expect(run.output[NUMSTAT]).toBe('2\t0\t.gitignore\n');
|
|
1565
|
+
expect(run.commitStatus).toBe(0);
|
|
1566
|
+
expect(gitOut(wt, 'rev-parse', 'HEAD~1').trim()).toBe(before);
|
|
1567
|
+
expect(showHead(wt)).toBe(`M\t.gitignore\nD\t${MARKER}\nD\t${CACHE}\n`);
|
|
1568
|
+
// notes.txt is untouched: on disk, untracked, not in the commit.
|
|
1569
|
+
expect(gitOut(wt, 'status', '--porcelain', '--', 'notes.txt')).toBe('?? notes.txt\n');
|
|
1570
|
+
expectUntrackedIgnoredOnDisk(wt);
|
|
1571
|
+
});
|
|
1572
|
+
it('criterion 1b, the Life Planner case: a marker and a cache file only staged give a commit of .gitignore alone', () => {
|
|
1573
|
+
const wt = makeRemedyFixture('staged-only');
|
|
1574
|
+
const before = headOf(wt);
|
|
1575
|
+
const run = followPrintedRemedy(wt);
|
|
1576
|
+
expect(run.stopped).toBeUndefined();
|
|
1577
|
+
expect(run.output[NUMSTAT]).toBe('2\t0\t.gitignore\n');
|
|
1578
|
+
expect(gitOut(wt, 'rev-parse', 'HEAD~1').trim()).toBe(before);
|
|
1579
|
+
expect(showHead(wt)).toBe('M\t.gitignore\n');
|
|
1580
|
+
expect(gitOut(wt, 'show', 'HEAD:.gitignore')).toBe(`.worktrees/\n${MARKER}\n.mx-coordination-token--*\n`);
|
|
1581
|
+
expect(stagedIn(wt)).toBe('');
|
|
1582
|
+
expectUntrackedIgnoredOnDisk(wt);
|
|
1583
|
+
});
|
|
1584
|
+
it('criterion 1c: an unrelated .gitignore edit already staged is printed by the check and the steps stop with nothing committed', () => {
|
|
1585
|
+
const wt = makeRemedyFixture('tracked');
|
|
1586
|
+
writeFileSync(join(wt, '.gitignore'), '.worktrees/\nbuild/\n');
|
|
1587
|
+
git(wt, 'add', '.gitignore');
|
|
1588
|
+
const before = headOf(wt);
|
|
1589
|
+
const run = followPrintedRemedy(wt);
|
|
1590
|
+
expect(run.stopped).toBe('M\t.gitignore\n');
|
|
1591
|
+
expect(headOf(wt)).toBe(before);
|
|
1592
|
+
// The operator's staged .gitignore is as they left it: no rule was added to it.
|
|
1593
|
+
expect(gitOut(wt, 'show', ':.gitignore')).toBe('.worktrees/\nbuild/\n');
|
|
1594
|
+
expect(readFileSync(join(wt, '.gitignore'), 'utf-8')).toBe('.worktrees/\nbuild/\n');
|
|
1595
|
+
});
|
|
1596
|
+
it('criteria 2 and 3: with nothing else staged, the commit is exactly the intended change and both files end untracked, ignored and on disk', () => {
|
|
1597
|
+
const wt = makeRemedyFixture('tracked');
|
|
1598
|
+
const before = headOf(wt);
|
|
1599
|
+
const run = followPrintedRemedy(wt);
|
|
1600
|
+
expect(run.stopped).toBeUndefined();
|
|
1601
|
+
expect(run.ran).toEqual(printedGitCommands());
|
|
1602
|
+
expect(run.output[NUMSTAT]).toBe('2\t0\t.gitignore\n');
|
|
1603
|
+
expect(gitOut(wt, 'rev-parse', 'HEAD~1').trim()).toBe(before);
|
|
1604
|
+
expect(gitOut(wt, 'log', '-1', '--format=%s').trim()).toBe(REMEDY_COMMIT_MESSAGE);
|
|
1605
|
+
expect(run.output[END_CHECK]).toBe(BOTH_IGNORED);
|
|
1606
|
+
expect(showHead(wt)).toBe(`M\t.gitignore\nD\t${MARKER}\nD\t${CACHE}\n`);
|
|
1607
|
+
expect(gitOut(wt, 'show', 'HEAD:.gitignore')).toBe(`.worktrees/\n${MARKER}\n.mx-coordination-token--*\n`);
|
|
1608
|
+
expect(stagedIn(wt)).toBe('');
|
|
1609
|
+
expectUntrackedIgnoredOnDisk(wt);
|
|
1610
|
+
});
|
|
1611
|
+
it('a second pass changes nothing: the commit finds nothing to commit and exits non-zero, as the text says', () => {
|
|
1612
|
+
const wt = makeRemedyFixture('tracked');
|
|
1613
|
+
followPrintedRemedy(wt);
|
|
1614
|
+
const after = headOf(wt);
|
|
1615
|
+
const again = followPrintedRemedy(wt, { nothingToCommit: true });
|
|
1616
|
+
expect(again.stopped).toBeUndefined();
|
|
1617
|
+
expect(again.output[NUMSTAT]).toBe('');
|
|
1618
|
+
expect(again.commitStatus).not.toBe(0);
|
|
1619
|
+
expect(headOf(wt)).toBe(after);
|
|
1620
|
+
expectUntrackedIgnoredOnDisk(wt);
|
|
1621
|
+
});
|
|
1622
|
+
it('QA M2: .gitignore already holds both lines, so step 2c prints nothing and step 2d commits only the removals', () => {
|
|
1623
|
+
const wt = makeRemedyFixture('tracked');
|
|
1624
|
+
writeFileSync(join(wt, '.gitignore'), `.worktrees/\n${MARKER}\n.mx-coordination-token--*\n`);
|
|
1625
|
+
git(wt, 'commit', '-q', '-m', 'the rules, committed earlier', '--', '.gitignore');
|
|
1626
|
+
const before = headOf(wt);
|
|
1627
|
+
const run = followPrintedRemedy(wt);
|
|
1628
|
+
expect(run.stopped).toBeUndefined();
|
|
1629
|
+
expect(run.output[NUMSTAT]).toBe('');
|
|
1630
|
+
expect(run.commitStatus).toBe(0);
|
|
1631
|
+
expect(gitOut(wt, 'rev-parse', 'HEAD~1').trim()).toBe(before);
|
|
1632
|
+
expect(showHead(wt)).toBe(`D\t${MARKER}\nD\t${CACHE}\n`);
|
|
1633
|
+
expectUntrackedIgnoredOnDisk(wt);
|
|
1634
|
+
});
|
|
1635
|
+
it('a staged marker whose name differs only in case is removed from the index by step 1 and never committed', () => {
|
|
1636
|
+
const wt = makeRemedyFixture('staged-only');
|
|
1637
|
+
// core.ignorecase is false on this fixture, so git tracks the two names apart.
|
|
1638
|
+
writeFileSync(join(wt, '.MX-Coordination-Team'), 'product\n');
|
|
1639
|
+
git(wt, 'add', '.MX-Coordination-Team');
|
|
1640
|
+
const run = followPrintedRemedy(wt, { extraIgnore: ['.MX-Coordination-Team'] });
|
|
1641
|
+
expect(run.stopped).toBeUndefined();
|
|
1642
|
+
expect(showHead(wt)).toBe('M\t.gitignore\n');
|
|
1643
|
+
expect(run.output[END_CHECK]).toBe(`!! .MX-Coordination-Team\n${BOTH_IGNORED}`);
|
|
1644
|
+
expect(gitOut(wt, 'ls-files', '--', '.MX-Coordination-Team')).toBe('');
|
|
1645
|
+
expect(existsSync(join(wt, '.MX-Coordination-Team'))).toBe(true);
|
|
1646
|
+
});
|
|
1647
|
+
it('security review of PR #561 (Should Fix): a committed, unchanged .MX-Coordination-Team ends untracked', () => {
|
|
1648
|
+
const wt = makeRemedyFixture('staged-only');
|
|
1649
|
+
writeFileSync(join(wt, '.MX-Coordination-Team'), 'product\n');
|
|
1650
|
+
git(wt, 'add', '.MX-Coordination-Team');
|
|
1651
|
+
git(wt, 'commit', '-q', '-m', 'a case-variant marker committed by mistake', '--', '.MX-Coordination-Team');
|
|
1652
|
+
expect(gitOut(wt, 'diff', '--cached', '--name-status', '--', '.MX-Coordination-Team')).toBe('');
|
|
1653
|
+
expect(defaultTrackedCoordinationFiles(wt)).toContain('.MX-Coordination-Team');
|
|
1654
|
+
const run = followPrintedRemedy(wt, { extraIgnore: ['.MX-Coordination-Team'] });
|
|
1655
|
+
expect(run.stopped).toBeUndefined();
|
|
1656
|
+
expect(showHead(wt)).toBe('D\t.MX-Coordination-Team\nM\t.gitignore\n');
|
|
1657
|
+
expect(run.output[END_CHECK]).toBe(`!! .MX-Coordination-Team\n${BOTH_IGNORED}`);
|
|
1658
|
+
expect(gitOut(wt, 'ls-files', '--', '.MX-Coordination-Team')).toBe('');
|
|
1659
|
+
expect(existsSync(join(wt, '.MX-Coordination-Team'))).toBe(true);
|
|
1660
|
+
expectUntrackedIgnoredOnDisk(wt);
|
|
1661
|
+
});
|
|
1662
|
+
it('security review of PR #561 (Must Fix, a): pasted in a subdirectory, the staged-only case commits no credential cache file', () => {
|
|
1663
|
+
const wt = makeRemedyFixture('staged-only');
|
|
1664
|
+
const before = headOf(wt);
|
|
1665
|
+
const run = followPrintedRemedy(wt, { cwd: join(wt, 'sub') });
|
|
1666
|
+
expect(run.stopped).toBeUndefined();
|
|
1667
|
+
expect(gitOut(wt, 'rev-parse', 'HEAD~1').trim()).toBe(before);
|
|
1668
|
+
const committed = gitOut(wt, 'show', '--name-only', '--format=', 'HEAD');
|
|
1669
|
+
expect(committed).not.toContain('.mx-coordination-token--');
|
|
1670
|
+
expect(committed).not.toContain(MARKER);
|
|
1671
|
+
expect(showHead(wt)).toBe('M\t.gitignore\n');
|
|
1672
|
+
expect(gitOut(wt, 'show', 'HEAD:sub/.gitignore')).toBe('*.log\n');
|
|
1673
|
+
expect(run.output[NUMSTAT]).toBe('2\t0\t.gitignore\n');
|
|
1674
|
+
expectUntrackedIgnoredOnDisk(wt);
|
|
1675
|
+
});
|
|
1676
|
+
it('security review of PR #561 (Must Fix, b): pasted in a subdirectory, the check prints a top-level staged notes.txt and the steps stop', () => {
|
|
1677
|
+
const wt = makeRemedyFixture('tracked');
|
|
1678
|
+
writeFileSync(join(wt, 'notes.txt'), 'the operator\'s own work\n');
|
|
1679
|
+
git(wt, 'add', 'notes.txt');
|
|
1680
|
+
const before = headOf(wt);
|
|
1681
|
+
const run = followPrintedRemedy(wt, { cwd: join(wt, 'sub') });
|
|
1682
|
+
expect(headOf(wt)).toBe(before);
|
|
1683
|
+
expect(stagedIn(wt)).toContain('A\tnotes.txt\n');
|
|
1684
|
+
expect(run.stopped).toBe('A\tnotes.txt\n');
|
|
1685
|
+
expect(run.ran).toEqual(throughCheck());
|
|
1686
|
+
});
|
|
1687
|
+
it('red-team on PR #561, item 1: a step 1 that removed nothing is caught by step 1a before any commit', () => {
|
|
1688
|
+
const wt = makeRemedyFixture('staged-only');
|
|
1689
|
+
const before = headOf(wt);
|
|
1690
|
+
const run = followPrintedRemedy(wt, { skipRemoval: true });
|
|
1691
|
+
// No commit, and the cache is still staged, not committed.
|
|
1692
|
+
expect(headOf(wt)).toBe(before);
|
|
1693
|
+
expect(stagedIn(wt)).toContain(`A\t${CACHE}\n`);
|
|
1694
|
+
expect(run.stoppedAt).toBe(printedGitCommands().find(isRemovalCheckStep));
|
|
1695
|
+
expect(run.stopped).toBe(`${MARKER}\n${CACHE}\n`);
|
|
1696
|
+
expect(run.output[END_CHECK]).toBeUndefined();
|
|
1697
|
+
});
|
|
1698
|
+
it('security Should Fix and QA W1 at 5f31405: a committed, unchanged cache file at step 2e is printed by the repeated listing, though status prints nothing for it', () => {
|
|
1699
|
+
const wt = makeRemedyFixture('tracked');
|
|
1700
|
+
// Someone re-adds the cache after step 1a; the step 2d commit then records it.
|
|
1701
|
+
const run = followPrintedRemedy(wt, { beforeCommit: () => git(wt, 'add', '-f', '--', CACHE) });
|
|
1702
|
+
expect(gitOut(wt, 'ls-files', '--', CACHE)).toBe(`${CACHE}\n`);
|
|
1703
|
+
expect(gitOut(wt, 'diff', 'HEAD', '--name-only', '--', CACHE)).toBe('');
|
|
1704
|
+
// The repeated listing at the start of step 2e prints it, and the steps stop there.
|
|
1705
|
+
expect(run.stopped).toBe(`${CACHE}\n`);
|
|
1706
|
+
expect(run.stoppedAt).toBe(printedGitCommands().find(isRemovalCheckStep));
|
|
1707
|
+
expect(run.ran).toEqual(printedGitCommands().slice(0, printedGitCommands().findIndex(isEndCheckStep)));
|
|
1708
|
+
// The status command alone would not have shown it: no line names the tracked, unchanged cache.
|
|
1709
|
+
const status = spawnSync('bash', ['-c', END_CHECK], { cwd: wt, encoding: 'utf-8', env: printedCommandEnv() });
|
|
1710
|
+
expect(status.stdout).toBe(`!! ${MARKER}\n`);
|
|
1711
|
+
});
|
|
1712
|
+
it('QA W3 at 5f31405: with an exact case-variant name added in step 2b, step 2c counts 3 added', () => {
|
|
1713
|
+
const wt = makeRemedyFixture('staged-only');
|
|
1714
|
+
writeFileSync(join(wt, '.MX-Coordination-Team'), 'product\n');
|
|
1715
|
+
git(wt, 'add', '.MX-Coordination-Team');
|
|
1716
|
+
const run = followPrintedRemedy(wt, { extraIgnore: ['.MX-Coordination-Team'] });
|
|
1717
|
+
expect(run.output[NUMSTAT]).toBe('3\t0\t.gitignore\n');
|
|
1718
|
+
});
|
|
1719
|
+
it('red-team on PR #561, item 2: a negation line in .gitignore shows in step 2e as files that are not ignored', () => {
|
|
1720
|
+
const wt = makeRemedyFixture('tracked');
|
|
1721
|
+
writeFileSync(join(wt, '.gitignore'), `.worktrees/\n${MARKER}\n.mx-coordination-token--*\n!.mx-*\n`);
|
|
1722
|
+
git(wt, 'commit', '-q', '-m', 'rules, then a negation that defeats them', '--', '.gitignore');
|
|
1723
|
+
const run = followPrintedRemedy(wt);
|
|
1724
|
+
expect(run.stopped).toBeUndefined();
|
|
1725
|
+
expect(showHead(wt)).toBe(`D\t${MARKER}\nD\t${CACHE}\n`);
|
|
1726
|
+
expect(run.output[END_CHECK]).toBe(`?? ${MARKER}\n?? ${CACHE}\n`);
|
|
1727
|
+
expect(gitOut(wt, 'ls-files', '--', MARKER, CACHE)).toBe('');
|
|
1728
|
+
});
|
|
1729
|
+
it('red-team on PR #561, item 2: step 2e runs from a subdirectory and reports top-level paths', () => {
|
|
1730
|
+
const wt = makeRemedyFixture('tracked');
|
|
1731
|
+
const run = followPrintedRemedy(wt, { cwd: join(wt, 'sub') });
|
|
1732
|
+
expect(run.output[END_CHECK]).toBe(BOTH_IGNORED);
|
|
1733
|
+
});
|
|
1734
|
+
it('criteria 4 and 5: no printed command discards or sweeps in other work, and every one is a constant', () => {
|
|
1735
|
+
const text = TRACKED_REMEDY.join('\n');
|
|
1736
|
+
const commands = printedGitCommands();
|
|
1737
|
+
expect(commands).toEqual([
|
|
1738
|
+
"git rm --cached -f --ignore-unmatch -- ':(top,icase,glob).mx-coordination-tea[m]' ':(top,icase,glob).mx-coordination-token--*'",
|
|
1739
|
+
"git ls-files -- ':(top,icase,glob).mx-coordination-tea[m]' ':(top,icase,glob).mx-coordination-token--*'",
|
|
1740
|
+
"git diff --cached --name-status -- ':(top)' ':(top,exclude,icase,glob).mx-coordination-tea[m]' ':(top,exclude,icase,glob).mx-coordination-token--*'",
|
|
1741
|
+
"git add ':(top).gitignore'",
|
|
1742
|
+
"git diff --cached --numstat -- ':(top).gitignore'",
|
|
1743
|
+
`git commit -m '${REMEDY_COMMIT_MESSAGE}'`,
|
|
1744
|
+
"git ls-files -- ':(top,icase,glob).mx-coordination-tea[m]' ':(top,icase,glob).mx-coordination-token--*'",
|
|
1745
|
+
"git status --porcelain --ignored=matching --untracked-files=all -- ':(top,icase,glob).mx-coordination-tea[m]' ':(top,icase,glob).mx-coordination-token--*'",
|
|
1746
|
+
]);
|
|
1747
|
+
const banned = [
|
|
1748
|
+
/\bgit\s+add\s+(-A|--all)\b/,
|
|
1749
|
+
/\bgit\s+add\s+\.(\s|$)/,
|
|
1750
|
+
/\bgit\s+commit\b[^`]*\s(-a|--all|-[a-zA-Z]*a[a-zA-Z]*)(\s|$)/,
|
|
1751
|
+
/\breset\b/,
|
|
1752
|
+
/\brestore\b/,
|
|
1753
|
+
/\bcheckout\s+--\s+\./,
|
|
1754
|
+
/\bstash\b/,
|
|
1755
|
+
/\bclean\b/,
|
|
1756
|
+
];
|
|
1757
|
+
for (const command of commands) {
|
|
1758
|
+
for (const pattern of banned)
|
|
1759
|
+
expect(command).not.toMatch(pattern);
|
|
1760
|
+
}
|
|
1761
|
+
// The prose names none of them either, so no operator reads one as an instruction.
|
|
1762
|
+
for (const pattern of banned)
|
|
1763
|
+
expect(text).not.toMatch(pattern);
|
|
1764
|
+
// The commit names no path: a pathspec commit takes paths from the working tree
|
|
1765
|
+
// and would re-add the marker step 1 removed from the index (red-team, v37).
|
|
1766
|
+
expect(commands.filter((c) => c.startsWith('git commit'))).toEqual([`git commit -m '${REMEDY_COMMIT_MESSAGE}'`]);
|
|
1767
|
+
// Each printed check pathspec survives the shell: bash passes git the exclude
|
|
1768
|
+
// patterns unexpanded, so a file named like the pattern is not substituted in.
|
|
1769
|
+
const check = commands.find(isCheckStep);
|
|
1770
|
+
const echoed = spawnSync('bash', ['-c', `printf '%s\\n' ${check.slice('git diff --cached --name-status -- '.length)}`], { cwd: base, encoding: 'utf-8' });
|
|
1771
|
+
expect(echoed.stdout).toBe(":(top)\n:(top,exclude,icase,glob).mx-coordination-tea[m]\n:(top,exclude,icase,glob).mx-coordination-token--*\n");
|
|
1772
|
+
// Every printed pathspec is anchored at the top of the worktree, so none depends on the current directory.
|
|
1773
|
+
for (const command of commands) {
|
|
1774
|
+
const pathspecs = command.includes(' -- ') ? command.slice(command.indexOf(' -- ') + 4).split(' ') : command.startsWith('git add ') ? [command.slice('git add '.length)] : [];
|
|
1775
|
+
for (const spec of pathspecs)
|
|
1776
|
+
expect(spec).toMatch(/^':\(top[,)]/);
|
|
1777
|
+
}
|
|
1778
|
+
});
|
|
1779
|
+
});
|
|
1312
1780
|
describe('security review at 2b8c8fd: the git calls', () => {
|
|
1313
1781
|
/** A script that leaves a sentinel file when git runs it. */
|
|
1314
1782
|
function sentinelScript(name) {
|