Repository navigation
feat(web-shell): add git commit history browser #7204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
55e2a64
feat(web-shell): add git commit history browser
wenshao 1ab9331
fix(web-shell): address review feedback on git log browser
wenshao 22f6f99
fix(web-shell): address R2 review feedback on git log browser
wenshao 712475d
fix(web-shell): count renamed files in commit detail + test git-log r…
38d29b9
fix(web-shell): address R3 review feedback on git log browser
wenshao ca08ca7
fix(web-shell): address R4 review feedback on git log browser
wenshao 877c64c
fix(web-shell): escape apostrophe in worktree welcome string
wenshao 6e28ed2
fix(web-shell): address git history review feedback
wenshao e30c12d
Merge branch 'main' into feat/webshell-git-log
wenshao a3a596b
test(web-shell): mock git diff content in app tests
wenshao 54dfda1
fix(core): harden git log metadata parsing
wenshao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
281 changes: 281 additions & 0 deletions
281
packages/cli/src/serve/routes/workspace-git-log.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,281 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Qwen Team | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import express from 'express'; | ||
| import request from 'supertest'; | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import { fetchGitLog, fetchGitCommitDetail } from '@qwen-code/qwen-code-core'; | ||
| import type { AcpSessionBridge } from '../acp-session-bridge.js'; | ||
| import { sendBridgeError } from '../server/error-response.js'; | ||
| import { | ||
| createWorkspaceRegistry, | ||
| type WorkspaceRegistry, | ||
| type WorkspaceRuntime, | ||
| } from '../workspace-registry.js'; | ||
| import { | ||
| registerWorkspaceGitLogRoutes, | ||
| registerWorkspaceQualifiedGitLogRoutes, | ||
| } from './workspace-git-log.js'; | ||
|
|
||
| vi.mock('@qwen-code/qwen-code-core', () => ({ | ||
| fetchGitLog: vi.fn(), | ||
| fetchGitCommitDetail: vi.fn(), | ||
| MAX_LOG_LIMIT: 200, | ||
| DEFAULT_LOG_LIMIT: 50, | ||
| })); | ||
|
|
||
| const fetchGitLogMock = vi.mocked(fetchGitLog); | ||
| const fetchGitCommitDetailMock = vi.mocked(fetchGitCommitDetail); | ||
|
|
||
| function runtime( | ||
| workspaceId: string, | ||
| workspaceCwd: string, | ||
| trusted: boolean, | ||
| ): WorkspaceRuntime { | ||
| return { | ||
| workspaceId, | ||
| workspaceCwd, | ||
| primary: workspaceId === 'primary', | ||
| trusted, | ||
| bridge: { publishWorkspaceEvent: vi.fn() } as unknown as AcpSessionBridge, | ||
| } as WorkspaceRuntime; | ||
| } | ||
|
|
||
| function registry(runtimes: WorkspaceRuntime[]): WorkspaceRegistry { | ||
| return createWorkspaceRegistry(runtimes); | ||
| } | ||
|
|
||
| const ENTRY = { | ||
| sha: 'abcdef1234567890abcdef1234567890abcdef12', | ||
| shortSha: 'abcdef1', | ||
| authorName: 'Test', | ||
| authorEmail: 't@example.com', | ||
| authorDate: 1_700_000_000, | ||
| subject: 'do a thing', | ||
| refs: 'HEAD -> main', | ||
| parents: ['0000000000000000000000000000000000000000'], | ||
| }; | ||
|
|
||
| describe('workspace Git log routes', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('returns the commit list for the bound workspace', async () => { | ||
| fetchGitLogMock.mockResolvedValue({ entries: [ENTRY], hasMore: true }); | ||
| const app = express(); | ||
| registerWorkspaceGitLogRoutes(app, { | ||
| boundWorkspace: '/work/main', | ||
| sendBridgeError, | ||
| }); | ||
|
|
||
| const response = await request(app).get('/workspace/git/log'); | ||
|
|
||
| expect(response.status).toBe(200); | ||
| expect(response.body).toMatchObject({ | ||
| v: 1, | ||
| workspaceCwd: '/work/main', | ||
| available: true, | ||
| hasMore: true, | ||
| entries: [ | ||
| { | ||
| sha: ENTRY.sha, | ||
| shortSha: 'abcdef1', | ||
| subject: 'do a thing', | ||
| refs: 'HEAD -> main', | ||
| parents: ENTRY.parents, | ||
| }, | ||
| ], | ||
| }); | ||
| }); | ||
|
|
||
| it('reports available=false when the workspace is not a git repo', async () => { | ||
| fetchGitLogMock.mockResolvedValue(null); | ||
| const app = express(); | ||
| registerWorkspaceGitLogRoutes(app, { | ||
| boundWorkspace: '/work/main', | ||
| sendBridgeError, | ||
| }); | ||
|
|
||
| const response = await request(app).get('/workspace/git/log'); | ||
|
|
||
| expect(response.status).toBe(200); | ||
| expect(response.body).toMatchObject({ | ||
| available: false, | ||
| entries: [], | ||
| hasMore: false, | ||
| }); | ||
| }); | ||
|
|
||
| it('clamps limit to MAX_LOG_LIMIT and passes skip through', async () => { | ||
| fetchGitLogMock.mockResolvedValue({ entries: [], hasMore: false }); | ||
| const app = express(); | ||
| registerWorkspaceGitLogRoutes(app, { | ||
| boundWorkspace: '/work/main', | ||
| sendBridgeError, | ||
| }); | ||
|
|
||
| await request(app).get('/workspace/git/log?limit=9999&skip=30'); | ||
|
|
||
| expect(fetchGitLogMock).toHaveBeenCalledWith('/work/main', { | ||
| limit: 200, | ||
| skip: 30, | ||
| }); | ||
| }); | ||
|
|
||
| it('falls back to the default limit for a non-numeric limit', async () => { | ||
| fetchGitLogMock.mockResolvedValue({ entries: [], hasMore: false }); | ||
| const app = express(); | ||
| registerWorkspaceGitLogRoutes(app, { | ||
| boundWorkspace: '/work/main', | ||
| sendBridgeError, | ||
| }); | ||
|
|
||
| await request(app).get('/workspace/git/log?limit=abc'); | ||
|
|
||
| expect(fetchGitLogMock).toHaveBeenCalledWith('/work/main', { | ||
| limit: 50, | ||
| skip: 0, | ||
| }); | ||
| }); | ||
|
|
||
| it('clamps a zero limit to one', async () => { | ||
| fetchGitLogMock.mockResolvedValue({ entries: [], hasMore: false }); | ||
| const app = express(); | ||
| registerWorkspaceGitLogRoutes(app, { | ||
| boundWorkspace: '/work/main', | ||
| sendBridgeError, | ||
| }); | ||
|
|
||
| await request(app).get('/workspace/git/log?limit=0'); | ||
|
|
||
| expect(fetchGitLogMock).toHaveBeenCalledWith('/work/main', { | ||
| limit: 1, | ||
| skip: 0, | ||
| }); | ||
| }); | ||
|
|
||
| it('returns commit detail for a valid sha', async () => { | ||
| fetchGitCommitDetailMock.mockResolvedValue({ | ||
| ...ENTRY, | ||
| body: 'the body', | ||
| files: [{ path: 'a.ts', added: 3, removed: 1, isBinary: false }], | ||
| filesCount: 1, | ||
| linesAdded: 3, | ||
| linesRemoved: 1, | ||
| hiddenCount: 0, | ||
| }); | ||
| const app = express(); | ||
| registerWorkspaceGitLogRoutes(app, { | ||
| boundWorkspace: '/work/main', | ||
| sendBridgeError, | ||
| }); | ||
|
|
||
| const response = await request(app).get( | ||
| `/workspace/git/log/commit?sha=${ENTRY.shortSha}`, | ||
| ); | ||
|
|
||
| expect(response.status).toBe(200); | ||
| expect(response.body).toMatchObject({ | ||
| available: true, | ||
| sha: ENTRY.sha, | ||
| body: 'the body', | ||
| files: [{ path: 'a.ts', added: 3, removed: 1, isBinary: false }], | ||
| filesCount: 1, | ||
| }); | ||
| expect(fetchGitCommitDetailMock).toHaveBeenCalledWith( | ||
| '/work/main', | ||
| ENTRY.shortSha, | ||
| ); | ||
| }); | ||
|
|
||
| it('rejects a missing sha with 400', async () => { | ||
| const app = express(); | ||
| registerWorkspaceGitLogRoutes(app, { | ||
| boundWorkspace: '/work/main', | ||
| sendBridgeError, | ||
| }); | ||
|
|
||
| const response = await request(app).get('/workspace/git/log/commit'); | ||
|
|
||
| expect(response.status).toBe(400); | ||
| expect(response.body).toMatchObject({ errorKind: 'parse_error' }); | ||
| expect(fetchGitCommitDetailMock).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('rejects a malformed (non-hex) sha with 400, distinct from a valid miss', async () => { | ||
| const app = express(); | ||
| registerWorkspaceGitLogRoutes(app, { | ||
| boundWorkspace: '/work/main', | ||
| sendBridgeError, | ||
| }); | ||
|
|
||
| const response = await request(app).get( | ||
| '/workspace/git/log/commit?sha=not-hex', | ||
| ); | ||
|
|
||
| // A 400 (not a 200 available:false) is what lets the client distinguish a | ||
| // bad request from a valid lookup that found no commit. | ||
| expect(response.status).toBe(400); | ||
| expect(response.body).toMatchObject({ errorKind: 'parse_error' }); | ||
| expect(fetchGitCommitDetailMock).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('reports available=false for a valid sha with no matching commit', async () => { | ||
| fetchGitCommitDetailMock.mockResolvedValue(null); | ||
| const app = express(); | ||
| registerWorkspaceGitLogRoutes(app, { | ||
| boundWorkspace: '/work/main', | ||
| sendBridgeError, | ||
| }); | ||
|
|
||
| const response = await request(app).get( | ||
| '/workspace/git/log/commit?sha=deadbee', | ||
| ); | ||
|
|
||
| expect(response.status).toBe(200); | ||
| expect(response.body).toMatchObject({ available: false }); | ||
| }); | ||
|
|
||
| it('rejects an untrusted workspace on the qualified routes', async () => { | ||
| const app = express(); | ||
| const primary = runtime('primary', '/work/main', true); | ||
| const untrusted = runtime('untrusted', '/work/untrusted', false); | ||
| registerWorkspaceQualifiedGitLogRoutes(app, { | ||
| workspaceRegistry: registry([primary, untrusted]), | ||
| sendBridgeError, | ||
| }); | ||
|
|
||
| const list = await request(app).get('/workspaces/untrusted/git/log'); | ||
| const detail = await request(app).get( | ||
| '/workspaces/untrusted/git/log/commit?sha=abcdef1', | ||
| ); | ||
|
|
||
| expect(list.status).toBe(403); | ||
| expect(detail.status).toBe(403); | ||
| expect(fetchGitLogMock).not.toHaveBeenCalled(); | ||
| expect(fetchGitCommitDetailMock).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('uses the selected trusted workspace runtime for the qualified log route', async () => { | ||
| fetchGitLogMock.mockResolvedValue({ entries: [], hasMore: false }); | ||
|
wenshao marked this conversation as resolved.
|
||
| const app = express(); | ||
| const primary = runtime('primary', '/work/main', true); | ||
| const secondary = runtime('secondary', '/work/secondary', true); | ||
| registerWorkspaceQualifiedGitLogRoutes(app, { | ||
| workspaceRegistry: registry([primary, secondary]), | ||
| sendBridgeError, | ||
| }); | ||
|
|
||
| const response = await request(app).get('/workspaces/secondary/git/log'); | ||
|
|
||
| expect(response.status).toBe(200); | ||
| expect(fetchGitLogMock).toHaveBeenCalledWith('/work/secondary', { | ||
| limit: 50, | ||
| skip: 0, | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.