Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions scripts/e2e-workspace-file-tracking.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -830,8 +830,8 @@ async function setupToolbar(fsOverrides = {}) {

const workerCalls = [];
const worker = { postMessage(msg) { workerCalls.push(msg); }, onmessage: null };
toolbar.initToolbar(worker, editorAPI, terminalAPI, fsAPI, () => {});
return { toolbar, document, worker, workerCalls, editorAPI, editorCalls, terminalAPI, terminalCalls, fsAPI, fsCalls };
const controller = toolbar.initToolbar(worker, editorAPI, terminalAPI, fsAPI, () => {});
return { toolbar, controller, document, worker, workerCalls, editorAPI, editorCalls, terminalAPI, terminalCalls, fsAPI, fsCalls };
}

function inlineInput(document) {
Expand Down Expand Up @@ -1118,6 +1118,14 @@ test('e2e: shortcut hints and keyboard shortcuts follow non-Mac conventions', as

// ── Run stop wiring + worker replacement ─────────────────────────────────────

test('e2e: initToolbar returns the worker lifecycle controller used after STOP', async () => {
const ctx = await setupToolbar();

assert.equal(typeof ctx.controller?.setWorker, 'function');
assert.equal(typeof ctx.controller?.getLastRunBinaryBytes, 'function');
assert.equal(typeof ctx.controller?.setRunPreparing, 'function');
});

test('e2e: STOP button delegates to the terminal stop action', async () => {
const ctx = await setupToolbar();

Expand All @@ -1141,9 +1149,9 @@ test('e2e: successful compile caches binary bytes for replacement-worker runs',
});
await tick();

assert.deepEqual([...ctx.toolbar.getLastRunBinaryBytes()], [7, 8, 9]);
assert.deepEqual([...ctx.controller.getLastRunBinaryBytes()], [7, 8, 9]);
bytes[0] = 99;
assert.deepEqual([...ctx.toolbar.getLastRunBinaryBytes()], [7, 8, 9], 'cached bytes are isolated from later mutation');
assert.deepEqual([...ctx.controller.getLastRunBinaryBytes()], [7, 8, 9], 'cached bytes are isolated from later mutation');
});

test('e2e: setWorker disconnects the old worker and binds messages to the replacement', async () => {
Expand All @@ -1152,7 +1160,7 @@ test('e2e: setWorker disconnects the old worker and binds messages to the replac
const oldWorker = ctx.worker;
const replacementWorker = { postMessage() {}, onmessage: null };

ctx.toolbar.setWorker(replacementWorker);
ctx.controller.setWorker(replacementWorker);

assert.equal(oldWorker.onmessage, null, 'old worker handler removed');
assert.equal(typeof replacementWorker.onmessage, 'function', 'replacement worker handler bound');
Expand Down
6 changes: 6 additions & 0 deletions src/ui/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ export function initToolbar(worker, editorAPI, terminalAPI, fsAPI, persistSessio
bindKeyboardShortcuts();
bindWorkspaceSyncEvents();
setWorker(worker);

return {
setWorker,
getLastRunBinaryBytes,
setRunPreparing,
};
}

export function setWorker(worker) {
Expand Down
Loading