@memnexus-ai/mx-agent-cli 0.1.296-next.3 → 0.1.296-next.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/__tests__/coordination-401-production-wiring.test.js +67 -1
  2. package/dist/__tests__/coordination-401-production-wiring.test.js.map +1 -1
  3. package/dist/__tests__/coordination-brief.test.js +58 -1
  4. package/dist/__tests__/coordination-brief.test.js.map +1 -1
  5. package/dist/__tests__/coordination-client.test.js +113 -1
  6. package/dist/__tests__/coordination-client.test.js.map +1 -1
  7. package/dist/__tests__/coordination-command.test.js +288 -2
  8. package/dist/__tests__/coordination-command.test.js.map +1 -1
  9. package/dist/__tests__/provision-completion-rows.test.js +329 -64
  10. package/dist/__tests__/provision-completion-rows.test.js.map +1 -1
  11. package/dist/__tests__/provision-resume.test.js +146 -0
  12. package/dist/__tests__/provision-resume.test.js.map +1 -1
  13. package/dist/__tests__/provision-row12-stub-server.test.d.ts +21 -0
  14. package/dist/__tests__/provision-row12-stub-server.test.d.ts.map +1 -0
  15. package/dist/__tests__/provision-row12-stub-server.test.js +262 -0
  16. package/dist/__tests__/provision-row12-stub-server.test.js.map +1 -0
  17. package/dist/__tests__/team-token-probe.test.d.ts +16 -0
  18. package/dist/__tests__/team-token-probe.test.d.ts.map +1 -0
  19. package/dist/__tests__/team-token-probe.test.js +295 -0
  20. package/dist/__tests__/team-token-probe.test.js.map +1 -0
  21. package/dist/commands/coordination.d.ts.map +1 -1
  22. package/dist/commands/coordination.js +48 -5
  23. package/dist/commands/coordination.js.map +1 -1
  24. package/dist/commands/create.d.ts +28 -10
  25. package/dist/commands/create.d.ts.map +1 -1
  26. package/dist/commands/create.js +123 -33
  27. package/dist/commands/create.js.map +1 -1
  28. package/dist/lib/coordination-client.d.ts +11 -0
  29. package/dist/lib/coordination-client.d.ts.map +1 -1
  30. package/dist/lib/coordination-client.js +79 -18
  31. package/dist/lib/coordination-client.js.map +1 -1
  32. package/dist/lib/coordination-token.d.ts +20 -0
  33. package/dist/lib/coordination-token.d.ts.map +1 -1
  34. package/dist/lib/coordination-token.js +1 -1
  35. package/dist/lib/coordination-token.js.map +1 -1
  36. package/dist/lib/team-token-probe.d.ts +120 -0
  37. package/dist/lib/team-token-probe.d.ts.map +1 -0
  38. package/dist/lib/team-token-probe.js +202 -0
  39. package/dist/lib/team-token-probe.js.map +1 -0
  40. package/dist/lib/templates.d.ts +1 -1
  41. package/dist/lib/templates.d.ts.map +1 -1
  42. package/dist/lib/templates.js +1 -1
  43. package/dist/standards/known-issues-standard.md +380 -0
  44. package/package.json +1 -1
@@ -305,8 +305,46 @@ vi.mock('../lib/vault.js', () => ({
305
305
  // boundary is stubbed by module, exactly as the vault read above is.
306
306
  vi.mock('../lib/coordination-token.js', () => ({
307
307
  usesCredentialEndpoint: (project) => credentialProjects.has(project),
308
- provisionCredentialForWorktree: vi.fn(async () => credentialState),
308
+ // `forceMint` is row 12's one re-mint after a cached token was answered 401
309
+ // (v41, condition R1). It answers `remintState`, so a test states the
310
+ // re-mint's outcome separately from the first one.
311
+ provisionCredentialForWorktree: vi.fn(async (i) => (i.forceMint === true ? remintState : credentialState)),
309
312
  }));
313
+ /**
314
+ * Row 12's probe (#15, v41). The REAL `probeTeamToken` runs: its classification,
315
+ * its dependency on row 10, its URL check and its one re-mint are the shipped
316
+ * code. Two things are injected, because a unit suite neither reads a token
317
+ * file nor opens a socket: the token read (a fake value) and the one request
318
+ * (`obligationsAnswers`, in call order, the last entry repeating).
319
+ */
320
+ let obligationsAnswers = [200];
321
+ /** The URL each probe request went to. The token is never recorded. */
322
+ let obligationsCalls = [];
323
+ let remintState = {
324
+ kind: 'obtainable',
325
+ cachePath: '/tmp/.mx-coordination-token--mx-agent--newteam',
326
+ mode: 0o600,
327
+ };
328
+ vi.mock('../lib/team-token-probe.js', async (importOriginal) => {
329
+ const real = await importOriginal();
330
+ const client = await vi.importActual('../lib/coordination-client.js');
331
+ return {
332
+ ...real,
333
+ probeTeamToken: vi.fn((i) => real.probeTeamToken({
334
+ ...i,
335
+ readToken: () => 'fake-team-token-for-tests-only',
336
+ getObligations: async ({ url }) => {
337
+ obligationsCalls.push(url);
338
+ const a = obligationsAnswers[Math.min(obligationsCalls.length - 1, obligationsAnswers.length - 1)];
339
+ if (a === 'timeout')
340
+ throw new client.ServiceUnreachableError(new Error('The operation was aborted'));
341
+ if (a >= 200 && a < 300)
342
+ return {};
343
+ throw new client.ServiceHttpError(a, 'service-error-text-for-tests');
344
+ },
345
+ })),
346
+ };
347
+ });
310
348
  vi.mock('../lib/memory.js', () => ({
311
349
  // create.ts reads this for the generated roleguide's codeContext (#83 B2).
312
350
  PROVISIONED_MEMORY_SERVICE: 'team-provisioning',
@@ -416,7 +454,10 @@ vi.mock('../lib/memory.js', () => ({
416
454
  exitCode: 0,
417
455
  }),
418
456
  }));
419
- vi.mock('../lib/project-config.js', () => ({
457
+ vi.mock('../lib/project-config.js', async (importOriginal) => ({
458
+ // Row 12's probe checks the URL with the real validator (v41): a permissive
459
+ // stand-in would let a test pass on a URL the shipped binary refuses.
460
+ validateCoordinationServiceUrl: (await importOriginal()).validateCoordinationServiceUrl,
420
461
  // Root-aware: '/unused' is what the mocked findProjectRoot returns, so a config
421
462
  // read at that root is a read of the WRONG project.
422
463
  loadProjectConfig: vi.fn((root) => ({ __root: root })),
@@ -496,6 +537,9 @@ beforeEach(() => {
496
537
  shapeReadFails = new Set();
497
538
  configuredProjectSlug = 'mx-agent';
498
539
  credentialState = OBTAINABLE;
540
+ remintState = { kind: 'obtainable', cachePath: '/tmp/.mx-coordination-token--mx-agent--newteam', mode: 0o600 };
541
+ obligationsAnswers = [200];
542
+ obligationsCalls = [];
499
543
  credentialProjects = new Set(['mx-agent']);
500
544
  extraConversationDiverges = false;
501
545
  preExistingContentFor = (name) => (name.endsWith('-leader-state') ? LEADER_SEED : '## log');
@@ -622,21 +666,23 @@ describe('completion check — the printed rows', () => {
622
666
  // the `team` the worktree records. This fixture writes
623
667
  // `.mx-code-context.json` for `newteam` at step 6a and the argument outranks
624
668
  // `CLAUDE_TEAM_NAME`, so the two agree whatever the environment of the
625
- // machine running the suite holds. Rows 11 and 12 are the ones this version
626
- // still does not look at.
669
+ // machine running the suite holds. Row 11 is the one this version still
670
+ // does not look at.
671
+ //
672
+ // Row 12 moved into the asserted group in v41 (#15): `provision` now makes
673
+ // one GET /obligations as the new team, and this fixture's injected probe
674
+ // answers 200.
627
675
  await provision();
628
676
  const lines = rowLines();
629
- for (const n of [0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 13]) {
677
+ for (const n of [0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 13]) {
630
678
  expect(lines[n]).toMatch(/row \d+: asserted/);
631
679
  }
632
680
  expect(lines[7]).toMatch(/row 7: could not run/);
633
681
  expect(lines[7]).not.toMatch(/not asserted/);
634
682
  expect(lines[11]).toMatch(/row 11: not asserted/);
635
683
  // #507: this fixture's project, `mx-agent`, takes the credential endpoint
636
- // and configures no URL, so the URL half of row 12 now resolves from the
637
- // built-in mx-agent service URL. The roster-and-token half is still not
638
- // checked, which is what `partly asserted` says.
639
- expect(lines[12]).toMatch(/row 12: partly asserted/);
684
+ // and configures no URL, so the probe went to the built-in mx-agent service
685
+ // URL, and the row says where the URL came from.
640
686
  expect(lines[12]).toContain('coordination URL from default');
641
687
  });
642
688
  it('names what each unasserted row would have covered', async () => {
@@ -646,7 +692,8 @@ describe('completion check — the printed rows', () => {
646
692
  expect(joined).toContain('mx-agent start newteam');
647
693
  expect(joined).toContain('roster entry');
648
694
  expect(joined).toContain('.mx-coordination-team');
649
- expect(joined).toContain('coordination brief');
695
+ // Row 12 asserts in this fixture (v41); what it names is the request it made.
696
+ expect(joined).toContain('GET /obligations');
650
697
  });
651
698
  it('an asserted row never carries a failure detail', async () => {
652
699
  // The printer shows `detail` on asserted rows too, so rows 1 and 2 must not
@@ -1182,13 +1229,14 @@ describe('completion check — each missing artifact exits non-zero naming its r
1182
1229
  const message = failure.message;
1183
1230
  for (const n of [1, 2, 3, 4, 5, 13])
1184
1231
  expect(message).toContain(`row ${n}:`);
1185
- // Ten required rows: 0 identity, 1 to 5, rows 9 and 10 since ;77, row 13
1186
- // since ;83, and row 14 since ;123. Six did not hold; the roster entry, the
1187
- // token and the build did. Row 13
1232
+ // Eleven required rows: 0 identity, 1 to 5, rows 9 and 10 since ;77, row 13
1233
+ // since ;83, row 14 since ;123, and row 12 on the credential-endpoint path
1234
+ // since v41 (#15). Six did not hold; the roster entry, the token, the token
1235
+ // probe and the build did. Row 13
1188
1236
  // is could-not-run here rather than failed: this fixture deletes the
1189
1237
  // roleguide copy the row reads, and a row that could not look is not a row
1190
1238
  // that passed.
1191
- expect(message).toContain('6 of the 10 rows');
1239
+ expect(message).toContain('6 of the 11 rows');
1192
1240
  expect(message).toContain('could not run');
1193
1241
  });
1194
1242
  });
@@ -1452,54 +1500,57 @@ describe('completion check — a pre-existing memory is diagnosed, never overwri
1452
1500
  //
1453
1501
  // Provisioning writes nothing to the operator's global config (#59 amendment).
1454
1502
  // What it does is report which level holds a URL, so a team created on a machine
1455
- // that has none is told so at creation instead of at its first brief.
1503
+ // that has none is told so at creation instead of at its first brief. Since v41
1504
+ // (#15) the row also makes one GET /obligations as the new team, and the URL
1505
+ // source is the second half of its detail. The hosts here end in `.memnexus.ai`
1506
+ // because the probe checks the URL with the real validator.
1456
1507
  describe('completion check — row 12', () => {
1457
1508
  it('reports the project config as the source on a machine that had no key', async () => {
1458
1509
  // The row names where the URL came FROM, not where it now sits: the seed
1459
1510
  // above has already written it into the operator config by this point.
1460
- configuredCoordinationUrl = 'https://coord.example.com';
1511
+ configuredCoordinationUrl = 'https://coord.memnexus.ai';
1461
1512
  await provision();
1462
1513
  const row12 = rowLines()[12];
1463
- expect(row12).toMatch(/row 12: partly asserted/);
1464
- expect(row12).toContain('coordination URL from project; roster and token not checked (#15)');
1465
- expect(row12).toContain('mx-agent coordination brief answers without "not registered"');
1514
+ expect(row12).toMatch(/row 12: asserted/);
1515
+ expect(row12).toContain('coordination URL from project');
1516
+ expect(row12).toContain('the new team\'s token authenticates to the coordination service (GET /obligations 200)');
1466
1517
  // The clean read path: nothing failed, so nothing warns.
1467
1518
  expect(stderrStream.join('')).toBe('');
1468
1519
  });
1469
1520
  it('reports the operator config as the source when that key is already set', async () => {
1470
- configuredCoordinationUrl = 'https://coord.example.com';
1471
- globalConfig.set('coordination-service-url', 'https://operators-own.example');
1521
+ configuredCoordinationUrl = 'https://coord.memnexus.ai';
1522
+ globalConfig.set('coordination-service-url', 'https://operators-own.memnexus.ai');
1472
1523
  await provision();
1473
- expect(rowLines()[12]).toMatch(/row 12: partly asserted/);
1474
- expect(rowLines()[12]).toContain('coordination URL from config; roster and token not checked (#15)');
1524
+ expect(rowLines()[12]).toMatch(/row 12: asserted/);
1525
+ expect(rowLines()[12]).toContain('coordination URL from config');
1475
1526
  });
1476
1527
  it('notes that the project declares a different URL, without printing either', async () => {
1477
1528
  // "coordination URL from config" reads as agreement when it says nothing
1478
1529
  // about the file the operator is looking at.
1479
- configuredCoordinationUrl = 'https://coord.example.com';
1480
- globalConfig.set('coordination-service-url', 'https://operators-own.example');
1530
+ configuredCoordinationUrl = 'https://coord.memnexus.ai';
1531
+ globalConfig.set('coordination-service-url', 'https://operators-own.memnexus.ai');
1481
1532
  await provision();
1482
1533
  const row12 = rowLines()[12];
1483
1534
  expect(row12).toContain('; note: mx-agent.config.json declares a different URL; the operator config takes precedence');
1484
- expect(row12).not.toContain('operators-own.example');
1485
- expect(row12).not.toContain('coord.example.com');
1535
+ expect(row12).not.toContain('operators-own.memnexus.ai');
1536
+ expect(row12).not.toContain('coord.memnexus.ai');
1486
1537
  });
1487
1538
  it('adds no note when the two levels agree, ignoring a trailing slash', async () => {
1488
- configuredCoordinationUrl = 'https://coord.example.com';
1489
- globalConfig.set('coordination-service-url', 'https://coord.example.com/');
1539
+ configuredCoordinationUrl = 'https://coord.memnexus.ai';
1540
+ globalConfig.set('coordination-service-url', 'https://coord.memnexus.ai/');
1490
1541
  await provision();
1491
1542
  expect(rowLines()[12]).toContain('coordination URL from config');
1492
1543
  expect(rowLines()[12]).not.toContain('declares a different URL');
1493
1544
  });
1494
1545
  it('adds no note when the project declares nothing', async () => {
1495
1546
  configuredCoordinationUrl = '';
1496
- globalConfig.set('coordination-service-url', 'https://operators-own.example');
1547
+ globalConfig.set('coordination-service-url', 'https://operators-own.memnexus.ai');
1497
1548
  await provision();
1498
1549
  expect(rowLines()[12]).toContain('coordination URL from config');
1499
1550
  expect(rowLines()[12]).not.toContain('declares a different URL');
1500
1551
  });
1501
1552
  it('adds no note when the project itself is the source', async () => {
1502
- configuredCoordinationUrl = 'https://coord.example.com';
1553
+ configuredCoordinationUrl = 'https://coord.memnexus.ai';
1503
1554
  await provision();
1504
1555
  expect(rowLines()[12]).toContain('coordination URL from project');
1505
1556
  expect(rowLines()[12]).not.toContain('declares a different URL');
@@ -1507,22 +1558,24 @@ describe('completion check — row 12', () => {
1507
1558
  });
1508
1559
  it('reads the project root provisioning was given, not the one the cwd implies', async () => {
1509
1560
  // `new project` runs from outside the project it scaffolds. Reading the cwd
1510
- // project returned another repository's URL: `partly asserted / from project`
1511
- // for a value from a file this project does not contain.
1512
- configuredCoordinationUrl = 'https://project-of-record.example';
1513
- decoyCwdCoordinationUrl = 'https://some-other-repository.example';
1561
+ // project returned another repository's URL: `from project` for a value
1562
+ // from a file this project does not contain.
1563
+ configuredCoordinationUrl = 'https://project-of-record.memnexus.ai';
1564
+ decoyCwdCoordinationUrl = 'https://some-other-repository.memnexus.ai';
1514
1565
  await provision();
1515
1566
  const row12 = rowLines()[12];
1516
1567
  expect(row12).toContain('coordination URL from project');
1517
1568
  // The mismatch note would fire if the resolved URL came from the decoy, since
1518
1569
  // the provisioned project's own config declares the other value.
1519
1570
  expect(row12).not.toContain('declares a different URL');
1571
+ // And the probe asked the project-of-record service, not the decoy.
1572
+ expect(obligationsCalls).toEqual(['https://project-of-record.memnexus.ai']);
1520
1573
  });
1521
1574
  it('is not asserted when only the cwd project has a URL', async () => {
1522
1575
  // A Key Vault project: it has no #507 fallback, so an absent URL stays absent.
1523
1576
  credentialProjects = new Set();
1524
1577
  configuredCoordinationUrl = '';
1525
- decoyCwdCoordinationUrl = 'https://some-other-repository.example';
1578
+ decoyCwdCoordinationUrl = 'https://some-other-repository.memnexus.ai';
1526
1579
  await provision();
1527
1580
  expect(rowLines()[12]).toMatch(/row 12: not asserted/);
1528
1581
  expect(rowLines()[12]).toContain('no coordination-service-url in env, config, or mx-agent.config.json');
@@ -1532,34 +1585,32 @@ describe('completion check — row 12', () => {
1532
1585
  credentialProjects = new Set();
1533
1586
  configuredCoordinationUrl = '';
1534
1587
  const { failure } = await provision();
1535
- // Not asserted is not a failure: row 12 has never been required.
1588
+ // Not a failure: row 12 is not required for a Key Vault project, which
1589
+ // provision does not probe (v41 plan item 5).
1536
1590
  expect(failure).toBeNull();
1537
1591
  const row12 = rowLines()[12];
1538
1592
  expect(row12).toMatch(/row 12: not asserted/);
1539
1593
  expect(row12).toContain('no coordination-service-url in env, config, or mx-agent.config.json');
1540
1594
  expect(row12).toContain('set coordinationServiceUrl in mx-agent.config.json');
1541
- expect(row12).toContain('roster and token not checked (#15)');
1595
+ expect(row12).not.toContain('roster and token not checked (#15)');
1542
1596
  });
1543
- it('a credential-endpoint project with no URL configured resolves the built-in mx-agent URL (#507)', async () => {
1597
+ it('a credential-endpoint project with no URL configured probes the built-in mx-agent URL (#507)', async () => {
1544
1598
  configuredCoordinationUrl = '';
1545
1599
  const { failure } = await provision();
1546
1600
  expect(failure).toBeNull();
1547
1601
  const row12 = rowLines()[12];
1548
- expect(row12).toMatch(/row 12: partly asserted/);
1602
+ expect(row12).toMatch(/row 12: asserted/);
1549
1603
  expect(row12).toContain('coordination URL from default');
1550
- expect(row12).toContain('roster and token not checked (#15)');
1604
+ expect(obligationsCalls).toEqual(['https://mxagent.dev.memnexus.ai']);
1551
1605
  });
1552
- it('counts as not asserted either way, so the asserted total stays 12 of 15', async () => {
1553
- configuredCoordinationUrl = 'https://coord.example.com';
1606
+ it('counts as asserted when the probe holds, so the asserted total is 13 of 16', async () => {
1607
+ configuredCoordinationUrl = 'https://coord.memnexus.ai';
1554
1608
  await provision();
1555
- // `partly asserted` is its own verdict, so it is not counted as asserted and
1556
- // it is not counted as not asserted either. The total the operator reads is
1557
- // the 12 rows this version checks: 7 before #77, rows 9 and 10, row 13, row
1558
- // 14 (#123), and row 8 since #428 part 3 gave it a real verdict.
1609
+ // 12 before v41: 7 before #77, rows 9 and 10, row 13, row 14 (#123), and
1610
+ // row 8 since #428 part 3. Row 12 is the thirteenth, now that it probes.
1559
1611
  const asserted = rowLines().filter((l) => /row \d+: asserted/.test(l));
1560
- expect(asserted).toHaveLength(12);
1561
- expect(rowLines()[12]).toMatch(/row 12: partly asserted/);
1562
- expect(rowLines()[12]).not.toMatch(/row 12: not asserted/);
1612
+ expect(asserted).toHaveLength(13);
1613
+ expect(rowLines()[12]).toMatch(/row 12: asserted/);
1563
1614
  expect(stderrStream.join('')).toBe('');
1564
1615
  });
1565
1616
  it('carries the source on the row, not only in the printed line', () => {
@@ -1572,17 +1623,18 @@ describe('completion check — row 12', () => {
1572
1623
  memoryNames: MEMORIES,
1573
1624
  mxAvailable: false,
1574
1625
  coordinationUrlSource: 'env',
1626
+ row12: { mode: 'probe', outcome: { kind: 'asserted', detail: 'GET /obligations answered 2xx to this team\'s token' } },
1575
1627
  });
1576
1628
  const row12 = rows.find((r) => r.n === 12);
1577
- expect(row12.asserted).toBe(false);
1578
- expect(row12.required).toBe(false);
1579
- expect(row12.urlAsserted).toBe(true);
1629
+ expect(row12.asserted).toBe(true);
1630
+ expect(row12.required).toBe(true);
1580
1631
  expect(row12.urlSource).toBe('env');
1581
1632
  printCompletionRows(rows);
1582
- expect(rowLines()[12]).toMatch(/row 12: partly asserted/);
1583
- expect(rowLines()[12]).toContain('coordination URL from env; roster and token not checked (#15)');
1633
+ expect(rowLines()[12]).toMatch(/row 12: asserted/);
1634
+ expect(rowLines()[12]).toContain('coordination URL from env');
1584
1635
  });
1585
- it('a caller that resolves no source gets the not-asserted line', () => {
1636
+ it('a caller that states no row-12 mode gets could-not-run, required, on the credential path', () => {
1637
+ // A caller that did not say is not a row that held.
1586
1638
  const rows = checkCompletionRows({
1587
1639
  slug: 'newteam',
1588
1640
  projectSlug: 'mx-agent',
@@ -1593,12 +1645,226 @@ describe('completion check — row 12', () => {
1593
1645
  mxAvailable: false,
1594
1646
  coordinationUrlSource: null,
1595
1647
  });
1596
- expect(rows.find((r) => r.n === 12).urlAsserted).toBe(false);
1648
+ const row12 = rows.find((r) => r.n === 12);
1649
+ expect(row12.asserted).toBe(false);
1650
+ expect(row12.required).toBe(true);
1651
+ expect(row12.couldNotRun).toBe(true);
1597
1652
  printCompletionRows(rows);
1598
- expect(rowLines()[12]).toMatch(/row 12: not asserted/);
1653
+ expect(rowLines()[12]).toMatch(/row 12: could not run/);
1599
1654
  expect(rowLines()[12]).toContain('no coordination-service-url in env, config, or mx-agent.config.json');
1600
1655
  });
1601
1656
  });
1657
+ // ── Row 12's token probe (#15; v41 plan criterion 1) ─────────────────────────
1658
+ //
1659
+ // One GET /obligations as the new team after row 10 cached its credential. The
1660
+ // injected request answers `obligationsAnswers`; everything else in
1661
+ // `probeTeamToken` and `checkCompletionRows` is the shipped code.
1662
+ describe('completion row 12 — the token probe (#15, v41)', () => {
1663
+ const CACHED = {
1664
+ kind: 'obtainable',
1665
+ cachePath: '/tmp/.mx-coordination-token--mx-agent--newteam',
1666
+ mode: 0o600,
1667
+ fromCache: true,
1668
+ };
1669
+ /** The serviceUrl each provisionCredentialForWorktree call was handed, and whether it forced a mint. */
1670
+ function mintCalls() {
1671
+ return vi.mocked(provisionCredentialForWorktree).mock.calls
1672
+ .map((c) => c[0]);
1673
+ }
1674
+ function everything() {
1675
+ return [...stdout, ...stderr, ...stderrStream].join('\n');
1676
+ }
1677
+ it('200: row 12 asserted, and the run prints Team Created!', async () => {
1678
+ obligationsAnswers = [200];
1679
+ const { failure } = await provision();
1680
+ expect(failure).toBeNull();
1681
+ expect(rowLines()[12]).toMatch(/row 12: asserted/);
1682
+ expect(rowLines()[12]).toContain('GET /obligations answered 2xx');
1683
+ expect(stdout.join('\n')).toContain('Team Created!');
1684
+ expect(obligationsCalls).toHaveLength(1);
1685
+ });
1686
+ for (const status of [401, 403, 404]) {
1687
+ it(`${status}: row 12 failed, the run exits non-zero, and no Team Created!`, async () => {
1688
+ obligationsAnswers = [status];
1689
+ const { failure } = await provision();
1690
+ expect(failure).not.toBeNull();
1691
+ expect(failure.message).toContain('row 12:');
1692
+ expect(stdout.join('\n')).not.toContain('Team Created!');
1693
+ expect(rowLines()[12]).toMatch(/row 12: not asserted/);
1694
+ expect(rowLines()[12]).toContain(`GET /obligations answered ${status}: the service refused this team's token`);
1695
+ // A fresh mint is not retried: only a CACHED token gets the one re-mint.
1696
+ expect(mintCalls()).toHaveLength(1);
1697
+ });
1698
+ }
1699
+ for (const answer of [503, 500, 429, 'timeout']) {
1700
+ it(`${answer}: row 12 could not run, the run exits non-zero, and no Team Created!`, async () => {
1701
+ obligationsAnswers = [answer];
1702
+ const { failure } = await provision();
1703
+ expect(failure).not.toBeNull();
1704
+ expect(failure.message).toContain('row 12:');
1705
+ expect(stdout.join('\n')).not.toContain('Team Created!');
1706
+ expect(rowLines()[12]).toMatch(/row 12: could not run/);
1707
+ expect(rowLines()[12]).toContain(answer === 'timeout' ? 'no answer (timeout or transport error)' : `GET /obligations answered ${answer}`);
1708
+ expect(mintCalls()).toHaveLength(1);
1709
+ });
1710
+ }
1711
+ it('a cached token answered 401 gets one re-mint, then 200: asserted', async () => {
1712
+ credentialState = CACHED;
1713
+ obligationsAnswers = [401, 200];
1714
+ const { failure } = await provision();
1715
+ expect(failure).toBeNull();
1716
+ expect(stdout.join('\n')).toContain('Team Created!');
1717
+ expect(rowLines()[12]).toMatch(/row 12: asserted/);
1718
+ expect(rowLines()[12]).toContain('the cached token was answered 401 and one re-mint ran');
1719
+ expect(obligationsCalls).toHaveLength(2);
1720
+ const calls = mintCalls();
1721
+ expect(calls).toHaveLength(2);
1722
+ expect(calls[0].forceMint).toBeUndefined();
1723
+ expect(calls[1].forceMint).toBe(true);
1724
+ // The re-mint went to the URL the first mint used.
1725
+ expect(calls[1].serviceUrl).toBe(calls[0].serviceUrl);
1726
+ // Row 10 reports the cache the team will read, which is the re-minted one.
1727
+ expect(rowLines()[10]).toContain('a credential was issued and cached');
1728
+ });
1729
+ it('a cached token answered 401, then 401 again after the re-mint: failed, and only one re-mint', async () => {
1730
+ credentialState = CACHED;
1731
+ obligationsAnswers = [401, 401];
1732
+ const { failure } = await provision();
1733
+ expect(failure).not.toBeNull();
1734
+ expect(stdout.join('\n')).not.toContain('Team Created!');
1735
+ expect(rowLines()[12]).toMatch(/row 12: not asserted/);
1736
+ expect(rowLines()[12]).toContain('one re-mint ran; GET /obligations answered 401');
1737
+ expect(obligationsCalls).toHaveLength(2);
1738
+ expect(mintCalls().filter((c) => c.forceMint === true)).toHaveLength(1);
1739
+ });
1740
+ it('a cached token answered 401 whose re-mint is refused: failed, no second request', async () => {
1741
+ credentialState = CACHED;
1742
+ remintState = { kind: 'refused', reason: 'not-authorized', detail: 'REFUSED-TEXT' };
1743
+ obligationsAnswers = [401];
1744
+ const { failure } = await provision();
1745
+ expect(failure).not.toBeNull();
1746
+ expect(rowLines()[12]).toMatch(/row 12: not asserted/);
1747
+ expect(rowLines()[12]).toContain('one re-mint did not produce a usable cache (refused)');
1748
+ expect(obligationsCalls).toHaveLength(1);
1749
+ });
1750
+ it('an issued re-mint whose cache write failed: row 10 reports the write failure, not the old cache (N-1)', async () => {
1751
+ credentialState = CACHED;
1752
+ remintState = {
1753
+ kind: 'could-not-run',
1754
+ detail: 'a credential was issued but it could not be written to the new worktree\'s token cache (WRITE-FAILED)',
1755
+ };
1756
+ obligationsAnswers = [401];
1757
+ const { failure } = await provision();
1758
+ expect(failure).not.toBeNull();
1759
+ expect(stdout.join('\n')).not.toContain('Team Created!');
1760
+ expect(rowLines()[10]).toMatch(/row 10: could not run/);
1761
+ expect(rowLines()[10]).toContain('WRITE-FAILED');
1762
+ expect(rowLines()[10]).not.toContain('a file is present at');
1763
+ expect(rowLines()[12]).toMatch(/row 12: not asserted/);
1764
+ expect(failure.message).toContain('row 10:');
1765
+ expect(failure.message).toContain('row 12:');
1766
+ });
1767
+ it('a cached token answered 403 is not re-minted: only 401 triggers it', async () => {
1768
+ credentialState = CACHED;
1769
+ obligationsAnswers = [403];
1770
+ await provision();
1771
+ expect(rowLines()[12]).toMatch(/row 12: not asserted/);
1772
+ expect(mintCalls()).toHaveLength(1);
1773
+ expect(obligationsCalls).toHaveLength(1);
1774
+ });
1775
+ it('row 10 not usable: row 12 "not run: depends on row 10", no request, and one fault is counted once', async () => {
1776
+ credentialState = { kind: 'refused', reason: 'not-authorized', detail: 'REFUSED-TEXT' };
1777
+ const { failure } = await provision();
1778
+ expect(obligationsCalls).toHaveLength(0);
1779
+ expect(rowLines()[12]).toMatch(/row 12: not asserted/);
1780
+ expect(rowLines()[12]).toContain('not run: depends on row 10');
1781
+ // The run fails on row 10, and row 12 is not listed beside it.
1782
+ expect(failure.message).toContain('row 10:');
1783
+ expect(failure.message).not.toContain('row 12:');
1784
+ });
1785
+ it('row 10 cached at the wrong mode: row 12 is not run either', async () => {
1786
+ credentialState = { kind: 'obtainable', cachePath: '/w/.mx-coordination-token--mx-agent--newteam', mode: 0o644 };
1787
+ await provision();
1788
+ expect(obligationsCalls).toHaveLength(0);
1789
+ expect(rowLines()[12]).toContain('not run: depends on row 10');
1790
+ });
1791
+ it('a Key Vault project is not probed, is not required, and names the brief step', async () => {
1792
+ credentialProjects = new Set();
1793
+ configuredCoordinationUrl = 'https://coord.memnexus.ai';
1794
+ const { failure } = await provision();
1795
+ expect(failure).toBeNull();
1796
+ expect(obligationsCalls).toHaveLength(0);
1797
+ expect(rowLines()[12]).toMatch(/row 12: not asserted/);
1798
+ expect(rowLines()[12]).toContain('run `mx-agent coordination brief` in the new worktree after its first `start`');
1799
+ const rows = checkCompletionRows({
1800
+ slug: 'newteam',
1801
+ projectSlug: 'memnexus',
1802
+ baseBranch: 'main',
1803
+ roleguideInWorktree: null,
1804
+ catalogEntry: join(root, 'nope.md'),
1805
+ memoryNames: MEMORIES,
1806
+ mxAvailable: false,
1807
+ coordinationUrlSource: 'project',
1808
+ });
1809
+ expect(rows.find((r) => r.n === 12).required).toBe(false);
1810
+ });
1811
+ it('the probe URL equals the mint URL', async () => {
1812
+ configuredCoordinationUrl = 'https://coord.memnexus.ai/';
1813
+ await provision();
1814
+ const mintUrl = mintCalls()[0].serviceUrl;
1815
+ expect(mintUrl).toBe('https://coord.memnexus.ai/');
1816
+ expect(obligationsCalls).toEqual([mintUrl.replace(/\/+$/, '')]);
1817
+ });
1818
+ it('a URL the validator refuses is could-not-run, makes no request, and does not echo the URL', async () => {
1819
+ process.env.MX_COORD_SERVICE_URL = 'http://not-allowed.example.com';
1820
+ try {
1821
+ const { failure } = await provision();
1822
+ expect(failure).not.toBeNull();
1823
+ expect(obligationsCalls).toHaveLength(0);
1824
+ expect(rowLines()[12]).toMatch(/row 12: could not run/);
1825
+ expect(rowLines()[12]).toContain('the coordination service URL was refused, so no request was made');
1826
+ expect(rowLines()[12]).not.toContain('not-allowed.example.com');
1827
+ }
1828
+ finally {
1829
+ delete process.env.MX_COORD_SERVICE_URL;
1830
+ }
1831
+ });
1832
+ it('prints status codes only: never the token, and never the text of a refusal', async () => {
1833
+ obligationsAnswers = [401];
1834
+ await provision();
1835
+ expect(everything()).not.toContain('fake-team-token-for-tests-only');
1836
+ // The injected ServiceHttpError carries a message standing in for the
1837
+ // service's `error` field; the row names the status in its own words and
1838
+ // never copies the message.
1839
+ expect(everything()).not.toContain('service-error-text-for-tests');
1840
+ });
1841
+ });
1842
+ // ── Row 12's mode is stated by the caller (bar-raiser Step 4 condition R2) ────
1843
+ describe('completion row 12 — the mode each caller states (R2)', () => {
1844
+ const base = {
1845
+ slug: 'newteam',
1846
+ projectSlug: 'mx-agent',
1847
+ baseBranch: 'main',
1848
+ roleguideInWorktree: null,
1849
+ memoryNames: MEMORIES,
1850
+ mxAvailable: false,
1851
+ coordinationUrlSource: 'project',
1852
+ };
1853
+ it('recheck: not run, not required, and says --recheck does not contact the service', () => {
1854
+ const rows = checkCompletionRows({ ...base, catalogEntry: join(root, 'nope.md'), row12: { mode: 'recheck' } });
1855
+ const row12 = rows.find((r) => r.n === 12);
1856
+ expect(row12.required).toBe(false);
1857
+ expect(row12.asserted).toBe(false);
1858
+ expect(row12.detail.startsWith('not run: --recheck does not contact the coordination service')).toBe(true);
1859
+ });
1860
+ it('failure handler: not run, not required, and says provision stopped before the probe', () => {
1861
+ const rows = checkCompletionRows({ ...base, catalogEntry: join(root, 'nope.md'), row12: { mode: 'not-run' } });
1862
+ const row12 = rows.find((r) => r.n === 12);
1863
+ expect(row12.required).toBe(false);
1864
+ expect(row12.asserted).toBe(false);
1865
+ expect(row12.detail.startsWith('not run: provision stopped before the probe')).toBe(true);
1866
+ });
1867
+ });
1602
1868
  /**
1603
1869
  * Row 2 with an `origin` (#51, plan #72).
1604
1870
  *
@@ -1608,7 +1874,7 @@ describe('completion check — row 12', () => {
1608
1874
  * two facts it asserted, and the asserted count does not move.
1609
1875
  */
1610
1876
  describe('completion row 2 — a project with an origin', () => {
1611
- it('asserts the entry on origin/main and still counts 12 of 15', async () => {
1877
+ it('asserts the entry on origin/main and still counts 13 of 15', async () => {
1612
1878
  hasOrigin = true;
1613
1879
  entryOnOriginMain = 'present';
1614
1880
  const { failure } = await provision();
@@ -1616,11 +1882,10 @@ describe('completion row 2 — a project with an origin', () => {
1616
1882
  expect(rowLines()).toHaveLength(16);
1617
1883
  expect(rowLines()[2]).toMatch(/row 2: asserted/);
1618
1884
  expect(rowLines()[2]).toContain('catalog entry on origin/main: mx-agent-system/teams/newteam.md');
1619
- // 12, not the 11 this asserted before #428 part 3: row 8 reports a real
1620
- // verdict now and this fixture's worktree records the team being
1621
- // provisioned. Row 2's own count is unchanged, which is what the test is
1622
- // about.
1623
- expect(rowLines().filter((l) => /row \d+: asserted/.test(l))).toHaveLength(12);
1885
+ // 13: 11 before #428 part 3 gave row 8 a real verdict, 12 until v41 (#15)
1886
+ // gave row 12 its token probe, which this fixture's injected probe answers
1887
+ // 200. Row 2's own count is unchanged, which is what the test is about.
1888
+ expect(rowLines().filter((l) => /row \d+: asserted/.test(l))).toHaveLength(13);
1624
1889
  });
1625
1890
  it('writes no catalog entry into the project root', async () => {
1626
1891
  // The write that produced the untracked file in the main checkout. The