fix: bind deploy progress, request, and health gate to the captured node (#1357)

* fix: bind deploy progress, request, and health gate to the captured node

A deploy/update/install/git-apply re-read the active node from localStorage
independently at three points: the progress WebSocket at mount, the POST at call
time, and the health-gate poll. If the active node changed between the click and
any of those, the operation, its live output, and its health verdict could
target different nodes, and the socket and POST splitting across nodes broke
output streaming.

Capture the operation's node once when it starts and thread it through every
leg. A new nodeId option on apiFetch overrides the active-node read, the
progress terminal takes a nodeId prop for its socket URL, the health gate polls
on the captured node, and a failed gate records its recovery entry only on the
node it ran on. The surface, the request, and the gate now always agree.

* fix: scope failed-gate recovery to the file list's node and harden node targeting

Addresses review findings on the captured-node binding:

- Track the node the stack file list was fetched for (filesNodeId) and record a
  failed gate's recovery entry only when it matches the gate's node. This closes
  a race where switching back to the gate's node could match a same-named stack
  from the previous node's still-loaded list before the new list lands, keying
  the record to the wrong file and blocking the correct one. refreshStacks now
  carries a sequence token so an out-of-order resolution cannot leave files and
  filesNodeId inconsistent.
- Make an explicit apiFetch nodeId authoritative over a caller-supplied
  x-node-id header.
- Add the missing stack-logs nodeId cases (null, and active-node fallback) to the
  terminal tests.
This commit is contained in:
Anso
2026-06-11 14:36:20 -04:00
committed by GitHub
parent a2fe58f62f
commit 48cebf9501
21 changed files with 617 additions and 51 deletions
@@ -90,8 +90,11 @@ function makeOverlay(over: Partial<OverlayState> = {}): OverlayState {
} as unknown as OverlayState;
}
const runWithLog: Parameters<typeof useStackActions>[0]['runWithLog'] = async (_p, run) =>
run(Promise.resolve(), 'test-session');
let lastRunWithLogParams: Parameters<Parameters<typeof useStackActions>[0]['runWithLog']>[0] | null = null;
const runWithLog: Parameters<typeof useStackActions>[0]['runWithLog'] = async (params, run) => {
lastRunWithLogParams = params;
return run(Promise.resolve(), 'test-session');
};
function setup(over: {
editorState?: Partial<EditorState>;
@@ -197,6 +200,44 @@ describe('useStackActions.handleSaveAndDeploy', () => {
});
});
describe('useStackActions node binding', () => {
const mouseEvent = { preventDefault: vi.fn(), stopPropagation: vi.fn() } as unknown as React.MouseEvent;
beforeEach(() => {
vi.mocked(apiFetch).mockReset();
vi.mocked(apiFetch).mockResolvedValue(new Response(null, { status: 200 }));
lastRunWithLogParams = null;
});
function postCallFor(fragment: string): RequestInit | undefined {
const call = vi.mocked(apiFetch).mock.calls.find(
c => String(c[0]).includes(fragment) && (c[1] as RequestInit | undefined)?.method === 'POST',
);
return call?.[1] as RequestInit | undefined;
}
it('binds the deploy POST and the runWithLog session to the captured node', async () => {
const { result } = setup(); // activeNode.id = 1
await result.current.deployStack(mouseEvent);
expect(postCallFor('/deploy')).toEqual(expect.objectContaining({ nodeId: 1 }));
expect(lastRunWithLogParams).toEqual(expect.objectContaining({ nodeId: 1 }));
});
it('binds the update POST and the runWithLog session to the captured node', async () => {
const { result } = setup();
await result.current.updateStack(mouseEvent);
expect(postCallFor('/update')).toEqual(expect.objectContaining({ nodeId: 1 }));
expect(lastRunWithLogParams).toEqual(expect.objectContaining({ nodeId: 1 }));
});
it('binds a non-update action (restart) POST and session to the captured node', async () => {
const { result } = setup();
await result.current.restartStack(mouseEvent);
expect(postCallFor('/restart')).toEqual(expect.objectContaining({ nodeId: 1 }));
expect(lastRunWithLogParams).toEqual(expect.objectContaining({ nodeId: 1 }));
});
});
describe('useStackActions policy-block dialog wiring', () => {
const policyPayload = {
error: 'Policy "block-high" blocked deploy: 1 image(s) exceed HIGH',