@memnexus-ai/mx-agent-cli 0.1.273 → 0.1.274

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 (26) hide show
  1. package/dist/__tests__/coordination-401-production-wiring.test.d.ts +19 -0
  2. package/dist/__tests__/coordination-401-production-wiring.test.d.ts.map +1 -0
  3. package/dist/__tests__/coordination-401-production-wiring.test.js +97 -0
  4. package/dist/__tests__/coordination-401-production-wiring.test.js.map +1 -0
  5. package/dist/__tests__/coordination-401-recovery.test.d.ts +22 -0
  6. package/dist/__tests__/coordination-401-recovery.test.d.ts.map +1 -0
  7. package/dist/__tests__/coordination-401-recovery.test.js +577 -0
  8. package/dist/__tests__/coordination-401-recovery.test.js.map +1 -0
  9. package/dist/__tests__/coordination-brief-pin.test.js +10 -2
  10. package/dist/__tests__/coordination-brief-pin.test.js.map +1 -1
  11. package/dist/__tests__/coordination-brief.test.js +9 -1
  12. package/dist/__tests__/coordination-brief.test.js.map +1 -1
  13. package/dist/__tests__/coordination-provision.test.js +17 -2
  14. package/dist/__tests__/coordination-provision.test.js.map +1 -1
  15. package/dist/__tests__/coordination-token.test.js +24 -0
  16. package/dist/__tests__/coordination-token.test.js.map +1 -1
  17. package/dist/agent-config/hooks/coordination-brief.sh +61 -9
  18. package/dist/commands/coordination.d.ts +40 -6
  19. package/dist/commands/coordination.d.ts.map +1 -1
  20. package/dist/commands/coordination.js +222 -10
  21. package/dist/commands/coordination.js.map +1 -1
  22. package/dist/lib/coordination-token.d.ts +104 -2
  23. package/dist/lib/coordination-token.d.ts.map +1 -1
  24. package/dist/lib/coordination-token.js +223 -42
  25. package/dist/lib/coordination-token.js.map +1 -1
  26. package/package.json +1 -1
@@ -0,0 +1,19 @@
1
+ /**
2
+ * #4970 — the PRODUCTION wiring of the 401-recovery wrapper.
3
+ *
4
+ * WHY THIS FILE EXISTS (security review of #4970). Every case in
5
+ * coordination-401-recovery.test.ts goes through prepareClient({ client }) — the
6
+ * INJECTED branch. The branch that actually ships is the provisioned one, which
7
+ * builds an HttpCoordinationClient and wraps it. The reviewer proved that branch
8
+ * was covered by nothing: replacing its `return withTokenRefresh(...)` with a
9
+ * bare `return new HttpCoordinationClient(cfg)` — i.e. removing 401 recovery from
10
+ * EVERY REAL INVOCATION — left the whole suite green. So the claim "all commands
11
+ * recover and fail loud" held for injected clients only.
12
+ *
13
+ * These tests reach that branch: the token module is mocked so no `az` or
14
+ * filesystem is touched, and HttpCoordinationClient is replaced with a stub whose
15
+ * drain 401s. If the wrapper is removed from the provisioned path, the 401
16
+ * escapes as a plain ServiceHttpError and both cases below fail.
17
+ */
18
+ export {};
19
+ //# sourceMappingURL=coordination-401-production-wiring.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coordination-401-production-wiring.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/coordination-401-production-wiring.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG"}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * #4970 — the PRODUCTION wiring of the 401-recovery wrapper.
3
+ *
4
+ * WHY THIS FILE EXISTS (security review of #4970). Every case in
5
+ * coordination-401-recovery.test.ts goes through prepareClient({ client }) — the
6
+ * INJECTED branch. The branch that actually ships is the provisioned one, which
7
+ * builds an HttpCoordinationClient and wraps it. The reviewer proved that branch
8
+ * was covered by nothing: replacing its `return withTokenRefresh(...)` with a
9
+ * bare `return new HttpCoordinationClient(cfg)` — i.e. removing 401 recovery from
10
+ * EVERY REAL INVOCATION — left the whole suite green. So the claim "all commands
11
+ * recover and fail loud" held for injected clients only.
12
+ *
13
+ * These tests reach that branch: the token module is mocked so no `az` or
14
+ * filesystem is touched, and HttpCoordinationClient is replaced with a stub whose
15
+ * drain 401s. If the wrapper is removed from the provisioned path, the 401
16
+ * escapes as a plain ServiceHttpError and both cases below fail.
17
+ */
18
+ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
19
+ // Mock the token module: prepareClient's provisioned branch requires a resolved
20
+ // token, and the refresh hook must be observable without reaching Key Vault.
21
+ vi.mock('../lib/coordination-token.js', () => ({
22
+ resolveCoordinationToken: vi.fn(),
23
+ refreshCoordinationToken: vi.fn(),
24
+ }));
25
+ // Replace ONLY the HTTP client class; keep the real error types and config
26
+ // resolution so the wrapper is exercised against the same shapes it sees live.
27
+ const constructedWith = [];
28
+ let drainImpl = async () => ({ messages: [], remaining: 0, batchId: '' });
29
+ vi.mock('../lib/coordination-client.js', async (importOriginal) => {
30
+ const actual = await importOriginal();
31
+ class StubHttpClient {
32
+ constructor(cfg) {
33
+ constructedWith.push(cfg.token ?? '');
34
+ }
35
+ drain() { return drainImpl(); }
36
+ async enqueue() { return { messageId: 'm', duplicate: false }; }
37
+ async confirmDrain() { }
38
+ async ack() { }
39
+ async history() { return { messages: [], nextBefore: '' }; }
40
+ async respondToMessage() { return { messageId: '', obligationState: 'resolved', stateNote: null, stateChangedAt: '' }; }
41
+ async getObligations() { return { owe: [], owed: [] }; }
42
+ }
43
+ return { ...actual, HttpCoordinationClient: StubHttpClient };
44
+ });
45
+ import { prepareClient, CoordinationAuthError, TOKEN_REJECTED_MARKER } from '../commands/coordination.js';
46
+ import { resolveCoordinationToken, refreshCoordinationToken } from '../lib/coordination-token.js';
47
+ import { ServiceHttpError } from '../lib/coordination-client.js';
48
+ const mockResolve = resolveCoordinationToken;
49
+ const mockRefresh = refreshCoordinationToken;
50
+ const savedEnv = { ...process.env };
51
+ beforeEach(() => {
52
+ constructedWith.length = 0;
53
+ mockResolve.mockReset();
54
+ mockRefresh.mockReset();
55
+ vi.spyOn(process.stderr, 'write').mockImplementation((() => true));
56
+ process.env.MX_COORDINATION_MODE = 'queue';
57
+ process.env.MX_COORD_SERVICE_URL = 'http://coordination.test';
58
+ delete process.env.MX_COORD_SERVICE_TOKEN;
59
+ mockResolve.mockReturnValue({ status: 'resolved', token: 'stale-token', project: 'memnexus', slug: 'platform', source: 'cache' });
60
+ });
61
+ afterEach(() => {
62
+ vi.restoreAllMocks();
63
+ process.env = { ...savedEnv };
64
+ });
65
+ describe('#4970 prepareClient — the PROVISIONED (shipping) client recovers and fails loud', () => {
66
+ it('a surviving 401 on the real client path is a LOUD CoordinationAuthError, and the token was refetched once', async () => {
67
+ drainImpl = async () => { throw new ServiceHttpError(401, 'invalid token'); };
68
+ mockRefresh.mockReturnValue({ status: 'refreshed', token: 'fresh-token', project: 'memnexus', slug: 'platform', source: 'keyvault', cacheInvalidated: true });
69
+ const client = prepareClient();
70
+ expect(client).not.toBeNull();
71
+ const err = await client.drain({}).then(() => null, (e) => e);
72
+ // MUTATION PIN: with the wrapper removed from coordination.ts's provisioned
73
+ // branch this is a bare ServiceHttpError and nothing refetches.
74
+ expect(err).toBeInstanceOf(CoordinationAuthError);
75
+ expect(err.message).toContain(TOKEN_REJECTED_MARKER);
76
+ expect(mockRefresh).toHaveBeenCalledTimes(1);
77
+ expect(mockRefresh).toHaveBeenCalledWith('stale-token');
78
+ // The retry ran against a REBUILT client carrying the fresh token.
79
+ expect(constructedWith).toEqual(['stale-token', 'fresh-token']);
80
+ });
81
+ it('the real client path self-heals: one 401, refetch, retry succeeds', async () => {
82
+ let n = 0;
83
+ drainImpl = async () => {
84
+ n++;
85
+ if (n === 1)
86
+ throw new ServiceHttpError(401, 'invalid token');
87
+ return { messages: [], remaining: 0, batchId: 'b1' };
88
+ };
89
+ mockRefresh.mockReturnValue({ status: 'refreshed', token: 'fresh-token', project: 'memnexus', slug: 'platform', source: 'keyvault' });
90
+ const res = await prepareClient().drain({});
91
+ expect(res).toEqual({ messages: [], remaining: 0, batchId: 'b1' });
92
+ expect(n).toBe(2);
93
+ expect(process.env.MX_COORD_SERVICE_TOKEN).toBe('fresh-token'); // in-memory only
94
+ expect(constructedWith).toEqual(['stale-token', 'fresh-token']);
95
+ });
96
+ });
97
+ //# sourceMappingURL=coordination-401-production-wiring.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coordination-401-production-wiring.test.js","sourceRo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@
1
+ /**
2
+ * #4970 — a REJECTED coordination token must never read as an empty inbox.
3
+ *
4
+ * Before this, resolveCoordinationToken returned the per-worktree cache
5
+ * unconditionally, nothing deleted that cache on an HTTP error, and runBrief
6
+ * called drain() with no handling at all. Post-rotation every team's session
7
+ * start would present the dead cached token forever with no self-heal, and the
8
+ * session-start hook discarded the failure entirely.
9
+ *
10
+ * THE DIRECTION THAT MATTERS (KI-METHOD-MUTATE-FAIL-OPEN). These tests are
11
+ * written to fail when the code goes back to being QUIET. The mutations they
12
+ * must catch are:
13
+ * - the client wrapper swallowing a 401 and returning an empty DrainResponse;
14
+ * - the second 401 being reported as anything other than a loud, non-zero,
15
+ * TOKEN_REJECTED failure;
16
+ * - refreshCoordinationToken keeping the stale cache file;
17
+ * - the recovery being wired into runBrief only, leaving drain/history silent.
18
+ * A test that only asserts the happy retry path would pass against every one of
19
+ * those, so each case below also asserts the ABSENCE of the reassuring output.
20
+ */
21
+ export {};
22
+ //# sourceMappingURL=coordination-401-recovery.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coordination-401-recovery.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/coordination-401-recovery.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG"}