From 42250c1be7386ea5eb9126e73936067c18778d75 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 22:28:05 +0000 Subject: [PATCH] Project evolution follows the checked-out history (S11, #83) The timeline is the first-parent history of HEAD, never --all, so stashes, notes and other branches are no longer frames (EVO-6). The whole history is listed (streamed) and thinned to 240 candidates from the first commit; a range is resolved by Git in either order, diverging ends from their merge base (EVO-7). Tags on trees or blobs are not offered. No 1000 clamp on the export's latest N, and the prompt names the branch's history (EVO-12). PROJECT_EVOLUTION_XR.md matches the code (EVO-19). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_014FkKtAtQus8TVjhG9bhytC --- .claude/docs/V1.2.1_STATUS.md | 6 + apps/vscode-extension/CHANGELOG.md | 6 + .../docs/features/PROJECT_EVOLUTION_XR.md | 42 +++- .../src/core/history/gitLineStream.ts | 80 +++++++ .../src/core/history/gitRepositoryService.ts | 146 +++++++----- .../core/history/projectEvolutionService.ts | 84 +------ .../core/history/projectEvolutionTimeline.ts | 142 ++++++++++++ .../active-analyses/activeAnalysesCommands.ts | 8 +- .../analysis/activeAnalysesActions.test.cjs | 2 +- .../analysis/activeAnalysesCommands.test.cjs | 6 +- .../test/analysis/gitListReferences.test.cjs | 13 +- .../test/analysis/gitTimeline.test.cjs | 208 ++++++++++++++++++ .../analysis/historicalComparison.test.cjs | 22 +- 13 files changed, 602 insertions(+), 163 deletions(-) create mode 100644 apps/vscode-extension/src/core/history/gitLineStream.ts create mode 100644 apps/vscode-extension/src/core/history/projectEvolutionTimeline.ts create mode 100644 apps/vscode-extension/test/analysis/gitTimeline.test.cjs diff --git a/.claude/docs/V1.2.1_STATUS.md b/.claude/docs/V1.2.1_STATUS.md index 723b7279..4ba4e63d 100644 --- a/.claude/docs/V1.2.1_STATUS.md +++ b/.claude/docs/V1.2.1_STATUS.md @@ -309,3 +309,9 @@ Then pushed `v1.2.1` to `origin` at the maintainer's request. **No merge and no **Measured**: `npm test` 1,139/1,139; ESLint 154 (unchanged); filesOver500 unchanged (`resolveEvolutionFrame`/`evolutionDirectoryOf` moved to `projectEvolutionArtifacts.ts`). Harnesses xr-mode, project-evolution (now asserts each frame loads `data.json` and that no bridge file exists) and xr pass. **Not done**: live evolution still materializes snapshots with one `git show` per file and runs the directory analysis per revision; reusing the export's blob pipeline (`GitTimelineBlobAnalyzer` + worker pool) needs a payload-parity check first and is left as follow-up. +### XR bug-fix epic #72 — S11 evolution follows the checked-out history (#83) [confirmed by unit tests on real repositories] (2026-11-25, branch `claude/project-thread-kvvyg6-history`) + +**What changed**: EVO-6, `listTimelineSources(maxCount, tip = 'HEAD', exclude?)` walks `git log --first-parent` of HEAD (or a range tip), never `--all`; the picker's commit list is `--branches --tags --remotes` (no stash, no notes). EVO-7, new `core/history/projectEvolutionTimeline.ts`: the Auto movie lists the whole first-parent history and thins it to `TIMELINE_SCAN_SAMPLE` = 240 spread over all of it (first and last kept), so the eligibility index and the picker cost what the old newest-240 window cost; a range is resolved by Git (`isAncestor`, `mergeBase`, `listTimelineSources(null, newer, older)`), in either order, diverging ends from their merge base; `resolveTimelineIndex` and `TIMELINE_SCAN_LIMIT` are gone; tags whose peeled object is not a commit are dropped. EVO-12, no 1000 clamp, and the timeline log is streamed through the new `core/history/gitLineStream.ts` (spawn + readline, same timeout, cancel signal and error codes as `runGit`); `countTimelineCommits` is `rev-list --first-parent --count HEAD`, 0 in an empty repository. The export prompt names the checked-out branch's history. EVO-19, `PROJECT_EVOLUTION_XR.md` rewritten for the timeline and the export. + +**Measured**: new `test/analysis/gitTimeline.test.cjs` (7 tests on real repositories: stash + notes + newer branch + detached HEAD, merge as one step, 300 commits sampled from the root with an old tag as range start, range in either order and across diverging branches, tree tag not offered, 1,100 commits with latest 1,050 returned, empty repository). Behaviour change for the export: other branches are no longer exported, by design of the story. + diff --git a/apps/vscode-extension/CHANGELOG.md b/apps/vscode-extension/CHANGELOG.md index b885add2..8d1acde7 100644 --- a/apps/vscode-extension/CHANGELOG.md +++ b/apps/vscode-extension/CHANGELOG.md @@ -103,6 +103,12 @@ - **Play** on the last frame starts the movie over instead of stopping at once, and reconnecting to the room keeps the frame you were on instead of jumping back to frame 1. - Manual movies always play from oldest to newest, as exported movies already did, whatever order the commits were picked in. A 25th pick is refused with a message instead of being dropped without notice. - The commit picker no longer lists the remote's default-branch alias as a branch named "origin". +- **Project evolution follows the history you have checked out.** + - The movie is now the history of the current branch from its first commit (first parent: a merge counts as one step). Before, it was every commit of every branch, so a `git stash` or a `git notes` entry could appear as a frame, and on an older checkout or a feature branch the movie played newer commits of other branches and then jumped back. + - Long histories start at the beginning. Before, only the newest 240 commits were considered, so a project with a long history never showed its first versions. + - A range now works with any branch, tag or commit the picker offers, in either order. Before, a tag older than the newest 240 commits failed with "project-evolution-range-not-found". Two ends on diverging branches start from their common ancestor. + - Tags that point at a file or a folder instead of a commit are no longer offered: they could not be used. + - Export: the Git timeline is the history of the checked-out branch, and the prompt says so. "Only the latest N commits" exports exactly N; before, N was silently cut to 1000, and a very large history could fail with "git timeline could not be listed". - A source file of the XR chart-mapping runtime contained a raw control character typed into a string. Behaviour was correct, but the file was invisible to code search and review tools. It now uses the equivalent escape sequence; the runtime value is identical. ## [1.2.0] - 2026-07-30 diff --git a/apps/vscode-extension/docs/features/PROJECT_EVOLUTION_XR.md b/apps/vscode-extension/docs/features/PROJECT_EVOLUTION_XR.md index 524b2302..dba9dc98 100644 --- a/apps/vscode-extension/docs/features/PROJECT_EVOLUTION_XR.md +++ b/apps/vscode-extension/docs/features/PROJECT_EVOLUTION_XR.md @@ -14,11 +14,21 @@ versions. - If the analyzed target is not inside a local Git repository, the option is disabled and explains the reason on hover/raycaster focus. - By default, CodeXR builds an automatic timeline from older commits to newer - commits. -- Large histories are sampled to a bounded number of frames so XR playback stays - usable. -- If the working copy has uncommitted changes, it can be used as the final live - frame. + commits: the **first-parent history of the checked-out branch (HEAD)**, from + its very first commit. A merge is one step of the branch it landed on. + Stashes, notes, other branches and commits newer than the checkout are never + frames (until 1.2.1 the timeline was `git log --all`). +- The whole history is listed and spread over at most 240 candidate revisions, + first and last included, then sampled to the movie's frames (24 by default), + so a long history always starts at its beginning. Until 1.2.1 only the newest + 240 commits were considered. +- A range movie is resolved by Git, not looked up in a window: any branch, tag + or commit the picker offers works as either end, in either order. Two ends on + diverging branches start from their merge base. The working copy as an end is + the last frame. +- Tags that point at a tree or a blob are not offered: they have no history. +- The movie always ends on the working copy, the branch as it stands now, + whether or not it has uncommitted changes. - The visualization uses a single chart occupying the normal analysis table, not the dual chart layout used by historical comparison. @@ -110,12 +120,28 @@ entity: } ``` -The browser runtime, `projectEvolutionRuntime.js`, listens for the shared entity -and keeps all connected clients on the same generated movie. +Which revisions a movie can show is decided by `projectEvolutionTimeline.ts` +(automatic and range timelines) over `GitRepositoryService.listTimelineSources`, +which streams `git log --first-parent` line by line, so a very large history +cannot overflow a buffer. + +The browser runtime, `projectEvolutionRuntime.js`, is assembled from the parts +listed in `templates/components/codexr/project-evolution/projectEvolutionRuntime/manifest.json`. +It listens for the shared entity and keeps all connected clients on the same +generated movie. + +### Export + +The export's Git timeline is the same history: the first-parent history of +HEAD. "Entire history" exports all of it, "Only the latest N commits" the +newest N, with no hidden cap (until 1.2.1 N was silently clamped to 1000). The +prompt says how many commits the checked-out branch has and that other +branches, stashes and notes are not exported. ## Initial Limits -- Version units are local Git commits. +- Version units are local Git commits of the checked-out branch's first-parent + history. - "Pushes" are represented by commits already present in the local repository. - GitHub, GitLab or other hosting provider APIs are not queried in this version. - Frames are precalculated before playback to avoid analysis work during the diff --git a/apps/vscode-extension/src/core/history/gitLineStream.ts b/apps/vscode-extension/src/core/history/gitLineStream.ts new file mode 100644 index 00000000..f6a86400 --- /dev/null +++ b/apps/vscode-extension/src/core/history/gitLineStream.ts @@ -0,0 +1,80 @@ +import * as childProcess from 'child_process'; +import * as readline from 'readline'; + +/** + * Runs `git -C cwd ...args` and hands stdout to `onLine` one line at a time + * (EVO-12). `execFile` buffers the whole output and fails past its + * `maxBuffer`, which a full `git log` of a very large history reaches; a + * stream has no such ceiling. Same timeout and cancel signal as the buffered + * runner, and the same error codes. + */ +export function streamGitLines( + cwd: string, + args: string[], + onLine: (line: string) => void, + options: { timeoutMs: number; signal?: AbortSignal; describeFailure: (error: unknown) => Error }, +): Promise { + return new Promise((resolve, reject) => { + let settled = false; + const finish = (error?: unknown) => { + if (settled) { + return; + } + settled = true; + clearTimeout(timer); + options.signal?.removeEventListener('abort', onAbort); + if (error === undefined) { + resolve(); + } else { + reject(options.describeFailure(error)); + } + }; + const child = childProcess.spawn('git', ['-C', cwd, ...args], { + windowsHide: true, + stdio: ['ignore', 'pipe', 'pipe'], + }); + const timer = setTimeout(() => { + child.kill(); + finish(Object.assign(new Error('git command timed out'), { killed: true })); + }, options.timeoutMs); + const onAbort = () => { + child.kill(); + finish(Object.assign(new Error('git command cancelled'), { name: 'AbortError' })); + }; + if (options.signal?.aborted) { + onAbort(); + return; + } + options.signal?.addEventListener('abort', onAbort, { once: true }); + + let stderr = ''; + child.stderr.setEncoding('utf8'); + child.stderr.on('data', (chunk: string) => { + // Only the head of stderr is kept: it is for the error message. + if (stderr.length < 4096) { + stderr += chunk; + } + }); + const lines = readline.createInterface({ input: child.stdout, crlfDelay: Infinity }); + lines.on('line', (line) => { + if (settled || !line) { + return; + } + try { + onLine(line); + } catch (error) { + child.kill(); + finish(error); + } + }); + child.on('error', (error) => finish(error)); + // 'close' fires after stdout ended, so every line was delivered. + child.on('close', (code) => { + if (code === 0) { + finish(); + } else { + finish(new Error(`git exited with code ${code}: ${stderr.trim()}`)); + } + }); + }); +} diff --git a/apps/vscode-extension/src/core/history/gitRepositoryService.ts b/apps/vscode-extension/src/core/history/gitRepositoryService.ts index 907b8917..ff9925ce 100644 --- a/apps/vscode-extension/src/core/history/gitRepositoryService.ts +++ b/apps/vscode-extension/src/core/history/gitRepositoryService.ts @@ -8,6 +8,7 @@ import { shouldIgnoreDirectoryName, } from '../analysis/watchers/analysisFilePolicy'; import { currentLaunchSignal } from '../analysis/launch/launchControl'; +import { streamGitLines } from './gitLineStream'; import type { ComparisonSource, GitReferenceType, @@ -79,12 +80,16 @@ export class GitRepositoryService { ])).stdout; const tagOutput = (await this.runGit(repositoryRoot, [ 'for-each-ref', - '--format=%(refname)%00%(*objectname)%00%(objectname)%00%(refname:short)%00%(*committerdate:short)%00%(committerdate:short)%00%(*committerdate:unix)%00%(committerdate:unix)', + '--format=%(refname)%00%(*objectname)%00%(objectname)%00%(refname:short)%00%(*committerdate:short)%00%(committerdate:short)%00%(*committerdate:unix)%00%(committerdate:unix)%00%(*objecttype)%00%(objecttype)', 'refs/tags', ])).stdout; const commitOutput = (await this.runGit(repositoryRoot, [ 'log', - '--all', + // Branches, tags and remotes, not `--all`: `--all` also walks + // refs/stash and refs/notes, whose commits are not history (EVO-6). + '--branches', + '--tags', + '--remotes', '--max-count=50', '--date=short', '--format=%H%x00%ad%x00%ct%x00%P%x00%s', @@ -146,55 +151,56 @@ export class GitRepositoryService { return { ...source, commitSha: resolved }; } - public async listTimelineSources(maxCount: number | null = 200): Promise { + /** + * Oldest first: the first-parent history of `tip` (HEAD), never `--all` + * (EVO-6), so stashes, notes and other branches are never frames. `exclude` + * stops the walk (a range start). No clamp, and streamed (EVO-12). + */ + public async listTimelineSources( + maxCount: number | null = 200, + tip = 'HEAD', + exclude?: string, + ): Promise { const repositoryRoot = await this.resolveRepositoryRoot(); - const limitArguments = maxCount === null - ? [] - : [`--max-count=${Math.max(1, Math.min(1000, Math.floor(maxCount)))}`]; - const commitLines = (await this.runGit(repositoryRoot, [ + if (!await this.revisionExists(repositoryRoot, tip)) { + return []; + } + const limitArguments = maxCount === null ? [] : [`--max-count=${Math.max(1, Math.floor(maxCount))}`]; + const sources: ComparisonSource[] = []; + await streamGitLines(repositoryRoot, [ 'log', - '--all', + '--first-parent', '--reverse', ...limitArguments, '--date=short', '--format=%H%x00%ad%x00%ct%x00%P%x00%s', - ])).stdout.split(/\r?\n/).filter(Boolean); - const sources: ComparisonSource[] = []; - for (const line of commitLines) { - const [commitSha, date, committerUnix, parents, subject] = line.split('\0'); - if (!this.isCommitSha(commitSha)) { - continue; + tip, + ...(exclude ? [`^${exclude}`] : []), + '--', + ], (line) => { + const source = this.parseCommitLine(line); + if (source) { + sources.push(source); } - const parentCount = this.countParents(parents); - sources.push(this.createGitSource( - 'commit', - commitSha, - commitSha.slice(0, 8), - commitSha, - `${date || ''} ${subject || ''}`.trim(), - parentCount > 1 ? 'merge' : 'commit', - parentCount, - date, - committerUnix, - )); - } + }, { timeoutMs: GIT_COMMAND_TIMEOUT_MS, signal: currentLaunchSignal(), describeFailure: describeGitFailure }); for (const source of sources) { this.sourceById.set(source.id, source); } return sources; } - /** - * Lightweight export preflight. Unlike listTimelineSources(), this does - * not enumerate or materialize commits; it only tells the user how much - * work the complete offline timeline will require. - */ + /** Export preflight: the commits listTimelineSources(null) would list. */ public async countTimelineCommits(): Promise { const repositoryRoot = await this.resolveRepositoryRoot(); + if (!await this.revisionExists(repositoryRoot, 'HEAD')) { + return 0; + } const rawCount = (await this.runGit(repositoryRoot, [ 'rev-list', - '--all', + '--first-parent', '--count', + 'HEAD', + '--', ])).stdout.trim(); const count = Number.parseInt(rawCount, 10); if (!Number.isFinite(count) || count < 0) { @@ -203,6 +209,28 @@ export class GitRepositoryService { return count; } + /** Whether `ancestor` is reachable from `descendant` (a commit is its own ancestor). */ + public async isAncestor(ancestor: string, descendant: string): Promise { + return this.isCommitSha(ancestor) && this.isCommitSha(descendant) && await this.tryRunGit( + await this.resolveRepositoryRoot(), ['merge-base', '--is-ancestor', ancestor, descendant], + ) !== null; + } + + /** The best common ancestor of two commits, or null for unrelated histories. */ + public async mergeBase(first: string, second: string): Promise { + const base = this.isCommitSha(first) && this.isCommitSha(second) + ? (await this.tryRunGit(await this.resolveRepositoryRoot(), ['merge-base', first, second]))?.stdout.trim() + : ''; + return base && this.isCommitSha(base) ? base : null; + } + + /** The commit HEAD points at, or null in an empty repository. */ + public async resolveHeadCommit(): Promise { + const head = await this.tryRunGit(await this.resolveRepositoryRoot(), ['rev-parse', '--verify', '--quiet', 'HEAD^{commit}']); + const sha = head?.stdout.trim() ?? ''; + return this.isCommitSha(sha) ? sha : null; + } + public async resolveSourcesInChronologicalOrder(sourceIds: string[]): Promise { if (!Array.isArray(sourceIds) || sourceIds.length === 0) { return []; @@ -476,8 +504,13 @@ export class GitRepositoryService { private parseTagRefs(stdout: string): ComparisonSource[] { const sources: ComparisonSource[] = []; for (const line of splitGitLines(stdout)) { - const [fullRef, peeledSha, objectSha, shortName, peeledDate, tagDate, peeledUnix, tagUnix] = line.split('\0'); + const [fullRef, peeledSha, objectSha, shortName, peeledDate, tagDate, peeledUnix, tagUnix, peeledType, objectType] = line.split('\0'); const commitSha = peeledSha || objectSha; + // A tag on a tree or a blob has no history to show and cannot be + // resolved as a commit: it is not offered (EVO-7). + if ((peeledType || objectType) !== 'commit') { + continue; + } if (!fullRef || !this.isCommitSha(commitSha) || !shortName) { continue; } @@ -488,26 +521,29 @@ export class GitRepositoryService { /** Recent commits from `git log`, merges typed as such. */ private parseCommitLog(stdout: string): ComparisonSource[] { - const sources: ComparisonSource[] = []; - for (const line of splitGitLines(stdout)) { - const [commitSha, date, committerUnix, parents, subject] = line.split('\0'); - if (!this.isCommitSha(commitSha)) { - continue; - } - const parentCount = this.countParents(parents); - sources.push(this.createGitSource( - 'commit', - commitSha, - commitSha.slice(0, 8), - commitSha, - `${date || ''} ${subject || ''}`.trim(), - parentCount > 1 ? 'merge' : 'commit', - parentCount, - date, - committerUnix, - )); + return splitGitLines(stdout) + .map((line) => this.parseCommitLine(line)) + .filter((source): source is ComparisonSource => source !== null); + } + + /** One `%H %ad %ct %P %s` log line (NUL-separated) as a commit source. */ + private parseCommitLine(line: string): ComparisonSource | null { + const [commitSha, date, committerUnix, parents, subject] = line.split('\0'); + if (!this.isCommitSha(commitSha)) { + return null; } - return sources; + const parentCount = this.countParents(parents); + return this.createGitSource( + 'commit', + commitSha, + commitSha.slice(0, 8), + commitSha, + `${date || ''} ${subject || ''}`.trim(), + parentCount > 1 ? 'merge' : 'commit', + parentCount, + date, + committerUnix, + ); } private createGitSource( @@ -563,6 +599,10 @@ export class GitRepositoryService { return relativePath.split(path.sep).join('/'); } + private async revisionExists(repositoryRoot: string, revision: string): Promise { + return (await this.tryRunGit(repositoryRoot, ['rev-parse', '--verify', '--quiet', `${revision}^{commit}`])) !== null; + } + private async gitObjectExists(repositoryRoot: string, objectSpec: string): Promise { try { await this.runGit(repositoryRoot, ['cat-file', '-e', objectSpec]); diff --git a/apps/vscode-extension/src/core/history/projectEvolutionService.ts b/apps/vscode-extension/src/core/history/projectEvolutionService.ts index 3d7fd9a2..7c73ea71 100644 --- a/apps/vscode-extension/src/core/history/projectEvolutionService.ts +++ b/apps/vscode-extension/src/core/history/projectEvolutionService.ts @@ -13,6 +13,7 @@ import { createGitAnalysisExclusion, } from './gitAnalysisEligibility'; import { sampleTimeline } from './gitTimelineSampler'; +import { buildAutomaticTimeline, buildRangeTimeline } from './projectEvolutionTimeline'; import { describeRevisionType, evolutionDirectoryOf, @@ -34,7 +35,6 @@ import { const ANALYZER_CACHE_VERSION = 'project-evolution-v1'; const DEFAULT_MAX_FRAMES = 24; const DEFAULT_ANALYSIS_CONCURRENCY = 4; -const TIMELINE_SCAN_LIMIT = 240; /** A whole movie longer than this is cancelled and reported (EVO-3). */ export const PROJECT_EVOLUTION_JOB_TIMEOUT_MS = 30 * 60 * 1000; @@ -86,7 +86,7 @@ export class ProjectEvolutionService { public async getReferences(): Promise { const references = await this.gitService.listReferences(); - const timeline = await this.buildAutomaticTimeline(references); + const timeline = await buildAutomaticTimeline(this.gitService, references); const mergedSources = mergeEvolutionSources(references.sources, timeline); const filtered = await this.analysis.sourceCatalog.filterSources({ repositoryRoot: references.repositoryRoot, @@ -377,81 +377,13 @@ export class ProjectEvolutionService { private async resolveAutomaticOrRangeSources( request: ProjectEvolutionRequest, ): Promise { - const timeline = await this.buildAutomaticTimeline(); - const mode = request.mode || 'auto'; - if (mode === 'range' && request.startSourceId && request.endSourceId) { - const startIndex = await this.resolveTimelineIndex(timeline, request.startSourceId); - const endIndex = await this.resolveTimelineIndex(timeline, request.endSourceId); - // A range the user asked for must never silently degrade into the - // full automatic movie — that is how "my range was not analyzed" - // presented. Unresolvable endpoints are a loud error instead. - if (startIndex < 0 || endIndex < 0) { - throw new Error('project-evolution-range-not-found'); - } - const from = Math.min(startIndex, endIndex); - const to = Math.max(startIndex, endIndex); - return timeline.slice(from, to + 1); - } - return timeline; - } - - /** - * Position of a picked source inside the commit timeline. - * - * The picker offers branches, tags and the working copy, whose ids do not - * exist in the commit-only timeline — so a direct id match is only the fast - * path. Otherwise the source is resolved to its commit sha (branches/tags - * point at one) and located by sha; the working copy means "the end". - */ - private async resolveTimelineIndex( - timeline: ComparisonSource[], - sourceId: string, - ): Promise { - const byId = timeline.findIndex((source) => source.id === sourceId); - if (byId >= 0) { - return byId; - } - if (sourceId === 'working-copy') { - return timeline.length - 1; - } - try { - const picked = await this.gitService.resolveSource(sourceId); - if (picked.kind !== 'gitRef' || !picked.commitSha) { - return -1; - } - return timeline.findIndex( - (source) => source.kind === 'gitRef' && source.commitSha === picked.commitSha, - ); - } catch { - return -1; - } - } - - private async buildAutomaticTimeline(existingReferences?: { sources: ComparisonSource[]; workingTreeDirty: boolean }): Promise { - const references = existingReferences ?? await this.gitService.listReferences(); - const timeline = await this.gitService.listTimelineSources(TIMELINE_SCAN_LIMIT); - const gitTimeline = timeline.length - ? timeline - : references.sources.filter((source) => source.kind === 'gitRef'); - const endAnchor = this.resolveCurrentStateSource(references); - if (endAnchor && !gitTimeline.some((source) => source.id === endAnchor.id)) { - return [...gitTimeline, endAnchor]; + const references = await this.gitService.listReferences(); + if ((request.mode || 'auto') === 'range' && request.startSourceId && request.endSourceId) { + // A range the user asked for never degrades into the automatic + // movie: an endpoint that cannot be resolved is a loud error. + return buildRangeTimeline(this.gitService, references, request.startSourceId, request.endSourceId); } - return gitTimeline; - } - - /** - * The revision a movie must finish on: the branch as it stands right now. - * - * That is the working copy — it is the checked-out branch whether or not the - * tree is dirty, and it is what the user is looking at. The timeline itself - * is `--all`, so its last entry may well belong to a different branch and - * cannot be trusted as the ending. - */ - private resolveCurrentStateSource( - references: { sources: ComparisonSource[]; workingTreeDirty: boolean }, - ): ComparisonSource | null { - return references.sources.find((source) => source.kind === 'workingCopy') || null; + return buildAutomaticTimeline(this.gitService, references); } private sampleSources(sources: ComparisonSource[], maxFrames: number): ComparisonSource[] { diff --git a/apps/vscode-extension/src/core/history/projectEvolutionTimeline.ts b/apps/vscode-extension/src/core/history/projectEvolutionTimeline.ts new file mode 100644 index 00000000..2de84c46 --- /dev/null +++ b/apps/vscode-extension/src/core/history/projectEvolutionTimeline.ts @@ -0,0 +1,142 @@ +/** + * Which revisions a project-evolution movie can show (S11, EVO-6/EVO-7). + * + * The timeline is the first-parent history of what is checked out, from its + * very first commit, ending on the working copy. It used to be the newest 240 + * commits of `git log --all`, so stashes and notes became frames, other + * branches newer than the checkout played before the "final" state, and a + * long history never reached its beginning. + * + * The whole history is listed (streamed, so its size is no problem) and then + * thinned to `TIMELINE_SCAN_SAMPLE` revisions spread over all of it, first and + * last included. That bound is what the eligibility index and the picker see, + * the same cost as the old window, but the window now spans the whole history. + */ +import { sampleTimeline } from './gitTimelineSampler'; +import { ComparisonSource } from './historicalComparisonModels'; + +/** How many revisions of the whole history are considered for a movie. */ +export const TIMELINE_SCAN_SAMPLE = 240; + +/** The part of GitRepositoryService the timeline needs. */ +export interface EvolutionTimelineGit { + listTimelineSources(maxCount: number | null, tip?: string, exclude?: string): Promise; + resolveSource(sourceId: string): Promise; + isAncestor(ancestor: string, descendant: string): Promise; + mergeBase(first: string, second: string): Promise; + resolveHeadCommit(): Promise; +} + +interface ReferenceListing { + sources: ComparisonSource[]; +} + +export const RANGE_NOT_FOUND_MESSAGE = + 'The start or the end of the range is no longer in this repository. Pick it again and generate.'; + +function workingCopyOf(references: ReferenceListing): ComparisonSource | null { + return references.sources.find((source) => source.kind === 'workingCopy') ?? null; +} + +/** Thins a chronological timeline to the scan sample, first and last kept. */ +function thin(timeline: ComparisonSource[]): ComparisonSource[] { + if (timeline.length <= TIMELINE_SCAN_SAMPLE) { + return timeline; + } + return sampleTimeline(timeline, TIMELINE_SCAN_SAMPLE, timeline[timeline.length - 1]); +} + +function endWith(timeline: ComparisonSource[], end: ComparisonSource | null): ComparisonSource[] { + if (end && !timeline.some((source) => source.id === end.id)) { + return [...timeline, end]; + } + return timeline; +} + +/** + * The Auto movie: HEAD's first-parent history from its first commit, ending + * on the working copy (the branch as it stands now, dirty or not). + */ +export async function buildAutomaticTimeline( + git: EvolutionTimelineGit, + references: ReferenceListing, +): Promise { + const history = await git.listTimelineSources(null); + return endWith(thin(history), workingCopyOf(references)); +} + +interface Endpoint { + sha: string; + live: boolean; +} + +async function resolveEndpoint(git: EvolutionTimelineGit, sourceId: string): Promise { + if (sourceId === 'working-copy') { + const head = await git.resolveHeadCommit(); + return head ? { sha: head, live: true } : null; + } + try { + const source = await git.resolveSource(sourceId); + if (source.kind === 'workingCopy') { + const head = await git.resolveHeadCommit(); + return head ? { sha: head, live: true } : null; + } + return source.commitSha ? { sha: source.commitSha, live: false } : null; + } catch { + return null; + } +} + +/** Older first: the working copy is always the newer end, else ancestry decides. */ +async function orderEndpoints( + git: EvolutionTimelineGit, + start: Endpoint, + end: Endpoint, +): Promise<{ older: Endpoint; newer: Endpoint }> { + if (start.live && !end.live) { + return { older: end, newer: start }; + } + const reversed = !end.live && start.sha !== end.sha + && !await git.isAncestor(start.sha, end.sha) + && await git.isAncestor(end.sha, start.sha); + return reversed ? { older: end, newer: start } : { older: start, newer: end }; +} + +/** The older end, or the merge base when the two ends diverge. */ +async function rangeStart(git: EvolutionTimelineGit, olderSha: string, newerSha: string): Promise { + if (olderSha === newerSha || await git.isAncestor(olderSha, newerSha)) { + return olderSha; + } + const base = await git.mergeBase(olderSha, newerSha); + if (!base) { + throw new Error('The two ends of the range share no history. Pick two revisions of the same project.'); + } + return base; +} + +/** + * A range movie: every first-parent step from the older endpoint to the newer + * one, resolved by Git rather than looked up in a window, so any branch, tag + * or commit the picker offers works (EVO-7). The endpoints may come in either + * order. Endpoints on diverging branches start from their merge base, so the + * movie is always one line of history. The working copy as an endpoint is the + * end of the movie. + */ +export async function buildRangeTimeline( + git: EvolutionTimelineGit, + references: ReferenceListing, + startSourceId: string, + endSourceId: string, +): Promise { + const start = await resolveEndpoint(git, startSourceId); + const end = await resolveEndpoint(git, endSourceId); + if (!start || !end) { + throw new Error(RANGE_NOT_FOUND_MESSAGE); + } + const { older, newer } = await orderEndpoints(git, start, end); + const fromSha = await rangeStart(git, older.sha, newer.sha); + const first = await git.listTimelineSources(1, fromSha); + const rest = fromSha === newer.sha ? [] : await git.listTimelineSources(null, newer.sha, fromSha); + const timeline = thin([...first, ...rest]); + return newer.live ? endWith(timeline, workingCopyOf(references)) : timeline; +} diff --git a/apps/vscode-extension/src/features/analysis/sections/active-analyses/activeAnalysesCommands.ts b/apps/vscode-extension/src/features/analysis/sections/active-analyses/activeAnalysesCommands.ts index af7e137b..a12359a3 100644 --- a/apps/vscode-extension/src/features/analysis/sections/active-analyses/activeAnalysesCommands.ts +++ b/apps/vscode-extension/src/features/analysis/sections/active-analyses/activeAnalysesCommands.ts @@ -449,18 +449,18 @@ export class ActiveAnalysesCommands { private async promptGitRevisionScope(commitCount: number): Promise { const scopeItem = await vscode.window.showQuickPick([ { - label: `Entire Git history — ${commitCount.toLocaleString()} commits`, - description: 'Every commit reachable from all branches and tags', + label: `Entire history of the checked-out branch — ${commitCount.toLocaleString()} commits`, + description: 'Every commit of HEAD from the first one (first parent: a merge is one step)', scope: { kind: 'all' } as GitRevisionScope, }, { label: 'Only the latest N commits…', - description: 'Newest commits across all branches and tags; working copy is added separately', + description: 'The newest commits of the checked-out branch; the working copy is added separately', scope: { kind: 'latest', count: 1 } as GitRevisionScope, }, ], { title: 'Export Git timeline: choose history range', - placeHolder: `${commitCount.toLocaleString()} commits are available`, + placeHolder: `${commitCount.toLocaleString()} commits on the checked-out branch. Other branches, stashes and notes are not exported.`, }); if (!scopeItem) { return undefined; diff --git a/apps/vscode-extension/test/analysis/activeAnalysesActions.test.cjs b/apps/vscode-extension/test/analysis/activeAnalysesActions.test.cjs index 38415ee9..9057c29e 100644 --- a/apps/vscode-extension/test/analysis/activeAnalysesActions.test.cjs +++ b/apps/vscode-extension/test/analysis/activeAnalysesActions.test.cjs @@ -161,7 +161,7 @@ test('the export modal decides what ships, before the destination is picked', () assert.match(source, /if \(selection\.gitTimeline\)/); assert.match(source, /exportGitRevisionData\(/); assert.match(source, /cancellable: true/); - assert.match(source, /Entire Git history/); + assert.match(source, /Entire history of the checked-out branch/); assert.match(source, /Only the latest N commits/); assert.match(source, /Balanced — \$\{balancedPlan\.workerCount\} workers/); assert.match(source, /Maximum speed — \$\{maximumPlan\.workerCount\} workers/); diff --git a/apps/vscode-extension/test/analysis/activeAnalysesCommands.test.cjs b/apps/vscode-extension/test/analysis/activeAnalysesCommands.test.cjs index 832a53f5..33010301 100644 --- a/apps/vscode-extension/test/analysis/activeAnalysesCommands.test.cjs +++ b/apps/vscode-extension/test/analysis/activeAnalysesCommands.test.cjs @@ -326,9 +326,9 @@ test('export wizard: the steps run in a fixed order and Continue Export comes ri assert.deepEqual(modes.items.map((item) => item.modeId), ['normal', 'dependency-graph', 'historical', 'evolution']); assert.equal(scope.title, 'Export Git timeline: choose history range'); - assert.equal(scope.placeHolder, `${(1234).toLocaleString()} commits are available`); + assert.equal(scope.placeHolder, `${(1234).toLocaleString()} commits on the checked-out branch. Other branches, stashes and notes are not exported.`); assert.deepEqual(scope.items.map((item) => item.label), [ - `Entire Git history — ${(1234).toLocaleString()} commits`, + `Entire history of the checked-out branch — ${(1234).toLocaleString()} commits`, 'Only the latest N commits…', ]); assert.deepEqual(scope.items.map((item) => item.scope), [{ kind: 'all' }, { kind: 'latest', count: 1 }]); @@ -361,7 +361,7 @@ test('export wizard: the entire history skips the count box and confirms the who inspect: () => ({ commitCount: 3 }), answers: [ (items) => items.filter((item) => item.modeId !== 'evolution'), - pick('Entire Git history'), + pick('Entire history of the checked-out branch'), pick('Balanced'), 'Continue Export', undefined, diff --git a/apps/vscode-extension/test/analysis/gitListReferences.test.cjs b/apps/vscode-extension/test/analysis/gitListReferences.test.cjs index b013c548..a96aee19 100644 --- a/apps/vscode-extension/test/analysis/gitListReferences.test.cjs +++ b/apps/vscode-extension/test/analysis/gitListReferences.test.cjs @@ -46,8 +46,8 @@ test('the git commands listReferences runs, in order', async () => { ['/repo', 'status', '--porcelain', '--untracked-files=normal', '--', 'src'], ['/repo', 'symbolic-ref', '--quiet', '--short', 'HEAD'], ['/repo', 'for-each-ref', '--format=%(refname)%00%(objectname)%00%(refname:short)%00%(committerdate:short)%00%(committerdate:unix)', 'refs/heads', 'refs/remotes'], - ['/repo', 'for-each-ref', '--format=%(refname)%00%(*objectname)%00%(objectname)%00%(refname:short)%00%(*committerdate:short)%00%(committerdate:short)%00%(*committerdate:unix)%00%(committerdate:unix)', 'refs/tags'], - ['/repo', 'log', '--all', '--max-count=50', '--date=short', '--format=%H%x00%ad%x00%ct%x00%P%x00%s'], + ['/repo', 'for-each-ref', '--format=%(refname)%00%(*objectname)%00%(objectname)%00%(refname:short)%00%(*committerdate:short)%00%(committerdate:short)%00%(*committerdate:unix)%00%(committerdate:unix)%00%(*objecttype)%00%(objecttype)', 'refs/tags'], + ['/repo', 'log', '--branches', '--tags', '--remotes', '--max-count=50', '--date=short', '--format=%H%x00%ad%x00%ct%x00%P%x00%s'], ]); }); @@ -65,9 +65,12 @@ test('every format parsed: branches, tags and commits after the working copy', a '', ].join('\r\n'), tags: [ - row('refs/tags/v2', sha('d'), sha('e'), 'v2', '2026-01-05', '2026-01-06', '1767600000', '1767700000'), - row('refs/tags/light', '', sha('a'), 'light', '', '2026-01-03', '', '1767400000'), - row('refs/tags/bad', '', 'zz', 'bad', '', '', '', ''), + row('refs/tags/v2', sha('d'), sha('e'), 'v2', '2026-01-05', '2026-01-06', '1767600000', '1767700000', 'commit', 'tag'), + row('refs/tags/light', '', sha('a'), 'light', '', '2026-01-03', '', '1767400000', '', 'commit'), + row('refs/tags/bad', '', 'zz', 'bad', '', '', '', '', '', 'commit'), + // S11 (EVO-7): tags on a tree or a blob cannot be resolved as a commit, so they are not offered. + row('refs/tags/tree-tag', '', sha('9'), 'tree-tag', '', '', '', '', '', 'tree'), + row('refs/tags/annotated-blob', sha('8'), sha('7'), 'annotated-blob', '', '', '', '', 'blob', 'tag'), ].join('\n'), commits: [ row(sha('a'), '2026-01-03', '1767400000', `${sha('b')} ${sha('f')}`, 'Merge feature'), diff --git a/apps/vscode-extension/test/analysis/gitTimeline.test.cjs b/apps/vscode-extension/test/analysis/gitTimeline.test.cjs new file mode 100644 index 00000000..79fcf02c --- /dev/null +++ b/apps/vscode-extension/test/analysis/gitTimeline.test.cjs @@ -0,0 +1,208 @@ +/** + * S11 (#83): the project-evolution timeline follows the history that is + * checked out (EVO-6, EVO-7, EVO-12). Runs the compiled GitRepositoryService + * and projectEvolutionTimeline against real temporary repositories. + */ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const os = require('node:os'); +const path = require('node:path'); +const childProcess = require('node:child_process'); + +const { GitRepositoryService } = require('../../out/core/history/gitRepositoryService.js'); +const { + TIMELINE_SCAN_SAMPLE, + buildAutomaticTimeline, + buildRangeTimeline, +} = require('../../out/core/history/projectEvolutionTimeline.js'); + +const roots = []; +test.after(() => roots.forEach((root) => fs.rmSync(root, { recursive: true, force: true }))); + +function git(cwd, args, env = {}) { + return childProcess.execFileSync('git', args, { + cwd, + encoding: 'utf8', + env: { ...process.env, ...env }, + stdio: ['pipe', 'pipe', 'pipe'], + }).trim(); +} + +function newRepository() { + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'codexr-git-timeline-')); + roots.push(root); + const repo = path.join(root, 'repo'); + fs.mkdirSync(repo); + git(repo, ['init', '--quiet', '--initial-branch=main']); + git(repo, ['config', 'user.name', 'CodeXR Tests']); + git(repo, ['config', 'user.email', 'codexr-tests@example.invalid']); + git(repo, ['config', 'commit.gpgsign', 'false']); + git(repo, ['config', 'tag.gpgsign', 'false']); + let clock = Date.parse('2024-01-01T00:00:00Z') / 1000; + const commit = (message, content = message) => { + fs.writeFileSync(path.join(repo, 'main.js'), `export const value = ${JSON.stringify(content)};\n`); + git(repo, ['add', '.']); + clock += 3600; + const date = `${clock} +0000`; + git(repo, ['commit', '--quiet', '-m', message], { GIT_AUTHOR_DATE: date, GIT_COMMITTER_DATE: date }); + return git(repo, ['rev-parse', 'HEAD']); + }; + const service = () => new GitRepositoryService(repo, path.join(root, `snapshots-${Math.random()}`)); + return { root, repo, commit, service }; +} + +/** `count` linear commits on main through fast-import: fast for big histories. */ +function bigRepository(count) { + const fixture = newRepository(); + const parts = []; + for (let index = 1; index <= count; index += 1) { + const message = `c${index}`; + const content = `export const value = ${index};\n`; + parts.push( + 'commit refs/heads/main', + `mark :${index}`, + `committer CodeXR Tests ${1700000000 + index * 60} +0000`, + `data ${Buffer.byteLength(message)}`, + message, + ...(index > 1 ? [`from :${index - 1}`] : []), + 'M 644 inline main.js', + `data ${Buffer.byteLength(content)}`, + content, + ); + } + childProcess.execFileSync('git', ['fast-import', '--quiet'], { + cwd: fixture.repo, + input: `${parts.join('\n')}\n`, + stdio: ['pipe', 'pipe', 'pipe'], + }); + git(fixture.repo, ['reset', '--quiet', '--hard', 'main']); + return fixture; +} + +const subjectOf = (source) => String(source.description || '').replace(/^\S+\s/, ''); + +test('S11 EVO-6: the timeline is HEAD\'s first-parent history; stashes, notes and other branches never become frames', async () => { + const { repo, commit, service } = newRepository(); + const c1 = commit('c1'); + const c2 = commit('c2'); + // Another branch, newer than HEAD. + git(repo, ['checkout', '--quiet', '-b', 'other']); + commit('other newer'); + git(repo, ['checkout', '--quiet', 'main']); + // A note and a stash. + git(repo, ['notes', 'add', '-m', 'a note', c2]); + fs.writeFileSync(path.join(repo, 'main.js'), 'export const value = "WIP";\n'); + git(repo, ['stash', 'push', '--quiet', '-m', 'WIP never committed']); + + const gitService = service(); + const timeline = await gitService.listTimelineSources(null); + assert.deepEqual(timeline.map((source) => source.commitSha), [c1, c2]); + const references = await gitService.listReferences(); + const subjects = references.sources.map(subjectOf).join('\n'); + assert.doesNotMatch(subjects, /WIP never committed|index on main|Notes added/); + const movie = await buildAutomaticTimeline(gitService, references); + assert.deepEqual(movie.map((source) => source.commitSha || source.id), [c1, c2, 'working-copy']); + + // Detached at c1: nothing newer than the checkout plays before the end. + git(repo, ['checkout', '--quiet', '--detach', c1]); + const detached = service(); + const detachedMovie = await buildAutomaticTimeline(detached, await detached.listReferences()); + assert.deepEqual(detachedMovie.map((source) => source.commitSha || source.id), [c1, 'working-copy']); +}); + +test('S11 EVO-6: a merge is one step of the branch it landed on', async () => { + const { repo, commit, service } = newRepository(); + const c1 = commit('c1'); + git(repo, ['checkout', '--quiet', '-b', 'feature']); + fs.writeFileSync(path.join(repo, 'side.js'), 'export const side = 1;\n'); + git(repo, ['add', 'side.js']); + git(repo, ['commit', '--quiet', '-m', 'side']); + const side = git(repo, ['rev-parse', 'HEAD']); + git(repo, ['checkout', '--quiet', 'main']); + const c2 = commit('c2'); + git(repo, ['merge', '--quiet', '--no-ff', '-m', 'merge feature', 'feature']); + const merge = git(repo, ['rev-parse', 'HEAD']); + const timeline = await service().listTimelineSources(null); + assert.deepEqual(timeline.map((source) => source.commitSha), [c1, c2, merge]); + assert.equal(timeline.at(-1).revisionType, 'merge'); + assert.ok(!timeline.some((source) => source.commitSha === side)); +}); + +test('S11 EVO-7: a long history is sampled from its first commit, and an old tag works as a range start', async () => { + const { repo, service } = bigRepository(300); + const shas = git(repo, ['rev-list', '--reverse', 'HEAD']).split('\n'); + git(repo, ['tag', 'v0.1', shas[4]]); + const gitService = service(); + const references = await gitService.listReferences(); + const movie = await buildAutomaticTimeline(gitService, references); + assert.equal(movie[0].commitSha, shas[0], 'the root commit opens the movie'); + assert.equal(movie.at(-2).commitSha, shas.at(-1), 'HEAD is the last commit'); + assert.equal(movie.at(-1).id, 'working-copy'); + assert.ok(movie.length <= TIMELINE_SCAN_SAMPLE + 1); + + const tag = references.sources.find((source) => source.label === 'v0.1'); + assert.ok(tag, 'the old tag is offered'); + const range = await buildRangeTimeline(gitService, references, tag.id, 'working-copy'); + assert.equal(range[0].commitSha, shas[4]); + assert.equal(range.at(-1).id, 'working-copy'); + // Same range picked in the other order. + const reversed = await buildRangeTimeline(gitService, references, 'working-copy', tag.id); + assert.deepEqual(reversed.map((source) => source.id), range.map((source) => source.id)); +}); + +test('S11 EVO-7: a range is resolved by Git: either order, and diverging ends start at their merge base', async () => { + const { repo, commit, service } = newRepository(); + const c1 = commit('c1'); + const c2 = commit('c2'); + const c3 = commit('c3'); + git(repo, ['checkout', '--quiet', '-b', 'feature', c2]); + const f1 = commit('f1'); + git(repo, ['checkout', '--quiet', 'main']); + const gitService = service(); + const references = await gitService.listReferences(); + await gitService.listTimelineSources(null); + const idOf = (sha) => references.sources.find((source) => source.commitSha === sha && source.refType === 'commit')?.id; + + const forward = await buildRangeTimeline(gitService, references, idOf(c1), idOf(c3)); + assert.deepEqual(forward.map((source) => source.commitSha), [c1, c2, c3]); + const backward = await buildRangeTimeline(gitService, references, idOf(c3), idOf(c1)); + assert.deepEqual(backward.map((source) => source.commitSha), [c1, c2, c3]); + const feature = references.sources.find((source) => source.refType === 'branch' && source.label === 'feature'); + const diverging = await buildRangeTimeline(gitService, references, idOf(c3), feature.id); + assert.deepEqual(diverging.map((source) => source.commitSha), [c2, f1]); + + await assert.rejects( + buildRangeTimeline(gitService, references, 'commit-does-not-exist', idOf(c3)), + /no longer in this repository/, + ); +}); + +test('S11 EVO-7: a tag on a tree is not offered by the picker', async () => { + const { repo, commit, service } = newRepository(); + commit('c1'); + git(repo, ['tag', 'tree-tag', 'HEAD^{tree}']); + git(repo, ['tag', 'good']); + const references = await service().listReferences(); + const tags = references.sources.filter((source) => source.refType === 'tag').map((source) => source.label); + assert.deepEqual(tags, ['good']); +}); + +test('S11 EVO-12: "latest N" is not clamped to 1000, and the count is the checked-out history', async () => { + const { service } = bigRepository(1100); + const gitService = service(); + assert.equal(await gitService.countTimelineCommits(), 1100); + const latest = await gitService.listTimelineSources(1050); + assert.equal(latest.length, 1050); + assert.equal(subjectOf(latest.at(-1)), 'c1100'); + assert.equal(subjectOf(latest[0]), 'c51'); + const all = await gitService.listTimelineSources(null); + assert.equal(all.length, 1100); +}); + +test('S11: an empty repository has an empty timeline and a zero count, not an error', async () => { + const { service } = newRepository(); + const gitService = service(); + assert.deepEqual(await gitService.listTimelineSources(null), []); + assert.equal(await gitService.countTimelineCommits(), 0); +}); diff --git a/apps/vscode-extension/test/analysis/historicalComparison.test.cjs b/apps/vscode-extension/test/analysis/historicalComparison.test.cjs index ffac6fc7..5c47d564 100644 --- a/apps/vscode-extension/test/analysis/historicalComparison.test.cjs +++ b/apps/vscode-extension/test/analysis/historicalComparison.test.cjs @@ -444,7 +444,6 @@ test('project evolution builds a chronological Git movie and publishes shared XR // Every worker ends before the job does: no orphan after a cancel (S6). assert.match(service, /Promise\.allSettled\(workers\)/); assert.match(service, /Analyzing \$\{sources\.length\} project revisions with \$\{concurrency\} workers/); - assert.match(service, /references\.sources\.filter\(\(source\) => source\.kind === 'gitRef'\)/); assert.match(service, /'project-evolution'/); assert.match(service, /path\.resolve\(staticRoot, 'evolution'\)/); assert.match(service, /path\.join\(evolutionDirectory, `revision-\$\{revision\}`\)/); @@ -464,20 +463,17 @@ test('project evolution builds a chronological Git movie and publishes shared XR assert.match(service, /fs\.promises\.rm\(this\.resolveEvolutionDirectory\(\), \{ recursive: true, force: true \}\)/); assert.match(service, /cancelAndWait/); // Frame selection is the shared sampler (even spacing in time, milestones - // preferred), and the movie always ends on the current state of the branch — - // the `--all` timeline's last entry can belong to another branch. + // preferred). The timeline is HEAD's first-parent history, ending on the + // working copy; a range is resolved by Git, and an endpoint that cannot be + // resolved throws instead of degrading to the automatic movie (S11). assert.match(service, /import \{ sampleTimeline \} from '\.\/gitTimelineSampler'/); assert.match(service, /return sampleTimeline\(sources, maxFrames/); - assert.match(service, /private resolveCurrentStateSource/); - assert.match(service, /source\.kind === 'workingCopy'\) \|\| null/); - // A picked range must be honoured or fail loudly: branch/tag/live endpoints - // are resolved by commit sha into the commit-only timeline, and an - // unresolvable endpoint throws instead of silently degrading to the full - // automatic movie (which is how "my range was not analyzed" presented). - assert.match(service, /private async resolveTimelineIndex/); - assert.match(service, /source\.commitSha === picked\.commitSha/); - assert.match(service, /sourceId === 'working-copy'[\s\S]{0,80}timeline\.length - 1/); - assert.match(service, /throw new Error\('project-evolution-range-not-found'\)/); + assert.match(service, /buildRangeTimeline\(this\.gitService, references, request\.startSourceId, request\.endSourceId\)/); + assert.doesNotMatch(service, /resolveTimelineIndex|TIMELINE_SCAN_LIMIT/); + const timeline = readProjectFile('src', 'core', 'history', 'projectEvolutionTimeline.ts'); + assert.match(timeline, /await git\.listTimelineSources\(null\)/); + assert.match(timeline, /source\.kind === 'workingCopy'\) \?\? null/); + assert.match(timeline, /throw new Error\(RANGE_NOT_FOUND_MESSAGE\)/); const sampler = readProjectFile('src', 'core', 'history', 'gitTimelineSampler.ts'); assert.match(sampler, /export function sampleTimeline/); assert.match(sampler, /function isMilestone/);