Skip to content
Open
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
24 changes: 24 additions & 0 deletions e2e/ui/03-workbench-settings.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,30 @@ test('desktop settings navigation reopens on the current page', async ({ page })
}
});

test('desktop settings returns keyboard focus after the reopened button becomes visible', async ({ page }) => {
await page.emulateMedia({ reducedMotion: 'reduce' });
await openView(page, 'settings');
const collapse = page.locator('#settingsSidebarToggle');
const expand = page.getByRole('button', { name: '展开设置导航', exact: true });
await expect(collapse).toBeVisible();
await collapse.press('Enter');
await expect(expand).toBeFocused();

const visibilityDelay = await page.addStyleTag({ content: '#settingsSidebarToggle { visibility: hidden !important; }' });
await expand.press('Enter');
await expect(page.locator('#settingsSidebar')).not.toHaveAttribute('aria-hidden', 'true');
await expect(collapse).toBeHidden();

// The sidebar can be expanded several frames before its button can take focus.
await page.evaluate(async () => {
for (let frame = 0; frame < 3; frame++) {
await new Promise(resolve => requestAnimationFrame(resolve));
}
});
await visibilityDelay.evaluate(style => style.remove());
await expect(collapse).toBeFocused();
});

test('personal credentials: the add wizard validates, saves write-only, and the row clears it', async ({ page, identity }) => {
const me = identity.user;
test.skip(!!(await userById(me.id))?.codexApiKeyConfigured, 'the token owner already has a Codex API Key; not overwriting a real credential');
Expand Down
4 changes: 4 additions & 0 deletions internal/repo/run_workspace_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ func (r *RunsRepo) ReleaseWorkspaceEditor(runID string, userID int64, beforeRele
return err
}
}
// Only clearing a legacy editor lease changes the persisted run.
if row.WorkspaceEditorID == 0 && row.WorkspaceEditUntil == nil {
return nil
}
return tx.Model(&runRow{}).Where("id = ?", runID).Updates(map[string]any{
"workspace_editor_id": 0, "workspace_edit_until": nil, "revision": gorm.Expr("revision + 1"),
}).Error
Expand Down
43 changes: 43 additions & 0 deletions internal/repo/run_workspace_edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,46 @@ func TestWorkspaceEditorTerminalRunsAndReleaseFailure(t *testing.T) {
}
}
}

func TestWorkspaceEditorReleaseOnlyUpdatesRunForLegacyLease(t *testing.T) {
st, err := OpenTest()
if err != nil {
t.Fatal(err)
}
defer st.Close()
const userID = 10
run := domain.Run{
ID: "editor-release",
Status: "running",
WorkspaceEditorID: userID,
WorkspaceEditUntil: time.Now().UTC().Add(time.Minute),
}
if err := st.PutRun(run); err != nil {
t.Fatal(err)
}
before, ok := st.RunState(run.ID)
if !ok {
t.Fatal("missing run")
}
closed := 0
closeTerminals := func(domain.Run) error {
closed++
return nil
}
if err := st.ReleaseWorkspaceEditor(run.ID, userID, closeTerminals); err != nil {
t.Fatal(err)
}
released, ok := st.RunState(run.ID)
if !ok || released.WorkspaceEditorID != 0 || !released.WorkspaceEditUntil.IsZero() || released.Revision != before.Revision+1 {
t.Fatalf("release should clear the legacy lease and increment the revision: %+v", released)
}
if err := st.ReleaseWorkspaceEditor(run.ID, userID, closeTerminals); err != nil {
t.Fatal(err)
}
if revision, ok := st.RunRevision(run.ID); !ok || revision != released.Revision {
t.Fatalf("release without a legacy lease changed the revision to %d, want %d", revision, released.Revision)
}
if closed != 2 {
t.Fatalf("release invoked terminal cleanup %d times, want 2", closed)
}
}
23 changes: 14 additions & 9 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1016,17 +1016,22 @@ function bind(){
}else switchView(btn.dataset.view);
});
$('#settingsSidebarToggle')?.addEventListener('click',()=>{cancelSettingsRouteTransition();setSettingsSidebarExpanded(!settingsSidebarExpanded())});
$('#settingsSidebarExpand')?.addEventListener('click',()=>{
$('#settingsSidebarExpand')?.addEventListener('click',event=>{
const opener=event.currentTarget;
cancelSettingsRouteTransition();
setSettingsSidebarExpanded(true);
requestAnimationFrame(()=>{
// Wait for the sidebar's descendants to inherit the restored visibility.
requestAnimationFrame(()=>{
if(settingsSidebarExpanded()&&document.activeElement===document.body){
$('#settingsSidebarToggle')?.focus({preventScroll:true});
}
});
});
const toggle=$('#settingsSidebarToggle');
if(!toggle)return;
const view=activeViewName();
const deadline=performance.now()+1000;
function restoreFocus(){
const active=document.activeElement;
if(!settingsSidebarExpanded()||activeViewName()!==view||(active!==document.body&&active!==opener))return;
// Visibility can lag behind the sidebar state, even with reduced motion.
toggle.focus({preventScroll:true});
if(document.activeElement!==toggle&&performance.now()<deadline)requestAnimationFrame(restoreFocus);
}
requestAnimationFrame(restoreFocus);
});
document.addEventListener('click',event=>{
if(document.body.classList.contains('management-mode')&&event.target instanceof Element&&event.target.closest('.collab-rail-toggle')){
Expand Down
35 changes: 20 additions & 15 deletions web/app/runs.js

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions webtest/tests/runs-detail.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,60 @@ test('run detail loads logs, telemetry, preview, workspace, evaluation, and chil
assert.match(app.document.querySelector('#runsView').textContent, /Implemented|Strong result|Report|2400|2\.4k/i);
});

test('live run redraws keep the current IDE document until the workspace is recycled', async (t) => {
const app = await loadApp();
t.after(app.close);
const run = {
...app.evaluate('structuredClone(state.data.runs[0])'),
status: 'running',
workflowSnapshot: app.evaluate('structuredClone(state.data.workflows[0])'),
nodes: {
'node-1': { status: 'succeeded', gateResult: { decision: 'pass' } },
'node-2': { status: 'running' },
},
};
const workspacePath = '/api/runs/run-1/workspace';
app.router.get('/api/runs/run-1', run);
app.router.get(workspacePath, { available: true, readOnly: false });
app.evaluate('state.data.runs=[' + JSON.stringify(run) + "];switchView('runs');showRunDetail('run-1')");
await settle(8);
const detail = app.document.querySelector('#runDetail');
detail.querySelector('[data-run-node="node-1"]').click();
detail.querySelector('[data-run-tab="workspace"]').click();
await settle(8);

const header = detail.querySelector('.run-detail-header');
const frame = detail.querySelector('[data-vscode-frame]');
const frameWindow = frame.contentWindow;
assert.ok(frameWindow);
const stream = app.evaluate('state.runStream');
stream.emit({ run: { ...run, revision: 2 } }, 'run');
assert.equal(detail.querySelector('.run-detail-header'), header, 'a passed gate needs no prompt');

const withOutput = {
...run,
revision: 3,
nodes: {
...run.nodes,
'node-1': { ...run.nodes['node-1'], output: 'New result' },
},
};
stream.emit({ run: withOutput }, 'run');
assert.notEqual(detail.querySelector('.run-detail-header'), header, 'new output redraws details');
assert.equal(detail.querySelector('.node-output pre').textContent, 'New result');
assert.equal(detail.querySelector('[data-vscode-frame]'), frame);
assert.ok(frame.contentWindow === frameWindow, 'detail redraw keeps the IDE browsing context');

app.evaluate('renderWorkspacePane(state.activeRun)');
assert.ok(frame.contentWindow === frameWindow, 'workspace render keeps the IDE browsing context');

app.router.get(workspacePath, { available: false, reason: '工作区已回收' });
stream.emit({ run: { ...withOutput, revision: 4, workspaceCleanedAt: '2026-11-23T08:00:00Z' } }, 'run');
await settle(8);
assert.equal(detail.querySelector('[data-vscode-frame]'), null);
assert.match(detail.querySelector('[data-run-pane="workspace"]').textContent, /工作区已回收/);
});

test('run detail node topology renders an icon glyph instead of undefined', async (t) => {
const app = await loadApp();
t.after(app.close);
Expand Down
Loading