Skip to content

The agent that grows with you

fix(desktop): keep the bundle-skew warning working on treeless checkouts

kshitijk4poora691b964c9a2
diff --git a/apps/desktop/electron/bundle-skew.test.ts b/apps/desktop/electron/bundle-skew.test.ts
index 6bf3d88a5ff..59e85601965 100644
--- a/apps/desktop/electron/bundle-skew.test.ts
+++ b/apps/desktop/electron/bundle-skew.test.ts
@@ -375,4 +375,43 @@ describe('detectBundleSkew against a real git repo', () => {
expect(packs()).toEqual(before)
expect(result).toEqual({ desktopCommitsBehind: null, outOfSync: false })
})
+
+ // An updated treeless install: the stamp and HEAD were both checked out, the
+ // commits between them never were, so their trees are missing and the walk
+ // fails. The endpoint diff still answers, offline.
+ it.each([
+ ['apps/desktop/src/app/new-feature.tsx', { desktopCommitsBehind: null, outOfSync: true }],
+ ['apps/desktop/README.md', { desktopCommitsBehind: null, outOfSync: false }]
+ ])('answers from the endpoints on a treeless clone when %s changed', async (file, expected) => {
+ const { repoRoot: origin } = makeScratchRepo()
+ const originGit = scratchGit(origin)
+
+ writeFiles(origin, ['apps/desktop/src/app/shell.tsx'])
+ originGit('add', '.')
+ originGit('commit', '-q', '-m', 'stamp')
+ const stamp = originGit('rev-parse', 'HEAD')
+ writeFiles(origin, ['apps/desktop/src/app/between.tsx'])
+ originGit('add', '.')
+ originGit('commit', '-q', '-m', 'between')
+ originGit('rm', '-q', 'apps/desktop/src/app/between.tsx')
+ writeFiles(origin, [file])
+ originGit('add', '.')
+ originGit('commit', '-q', '-m', 'head')
+ originGit('config', 'uploadpack.allowFilter', 'true')
+
+ const clone = mkdtempSync(join(tmpdir(), 'bundle-skew-clone-'))
+ scratchRepos.push(clone)
+ execFileSync('git', ['clone', '-q', '--filter=tree:0', `file://${origin}`, clone], {
+ stdio: ['ignore', 'pipe', 'pipe']
+ })
+ scratchGit(clone)('checkout', '-q', stamp)
+ scratchGit(clone)('checkout', '-q', 'main')
+ const packs = () => readdirSync(join(clone, '.git/objects/pack')).sort()
+ const before = packs()
+
+ const result = await detectBundleSkew({ commit: stamp, source: 'local' }, realGitRun(clone), clone)
+
+ expect(packs()).toEqual(before)
+ expect(result).toEqual(expected)
+ })
})
diff --git a/apps/desktop/electron/bundle-skew.ts b/apps/desktop/electron/bundle-skew.ts
index 2a389e132ac..ff48d6f3545 100644
--- a/apps/desktop/electron/bundle-skew.ts
+++ b/apps/desktop/electron/bundle-skew.ts
@@ -154,15 +154,10 @@ export async function detectBundleSkew(
// Exit 0 = ancestor, 1 = unrelated or diverged, anything else = git could
// not answer (unknown object, shallow clone, not a repo). Only the first
- // makes the commit count below a statement about skew, and the other two
- // are the same "unknowable" the branches above already answer quietly.
- //
- // Deliberately not falling back to comparing apps/desktop CONTENT here.
- // Differing content would prove the build and the tree disagree, but not
- // which way round: a user sitting on an older checkout than their build
- // would be told "app build out of date" backwards. Ancestry is what makes
- // this a proof that the renderer PREDATES the tree, which is the claim the
- // warning actually makes.
+ // makes the checks below a statement about skew, and the other two are the
+ // same "unknowable" the branches above already answer quietly. Ancestry is
+ // also what gives a content comparison a direction: without it, differing
+ // content could mean the checkout is OLDER than the build.
const ancestry = await runGit(['merge-base', '--is-ancestor', stamp.commit, 'HEAD'], options)
if (ancestry.code !== 0) {
@@ -172,7 +167,15 @@ export async function detectBundleSkew(
const result = await runGit(['rev-list', '--count', `${stamp.commit}..HEAD`, '--', ...RUNTIME_PATHS], options)
if (result.code !== 0) {
- return NOT_STALE
+ // A treeless (tree:0) checkout holds trees only for commits it checked
+ // out: the walk above needs every intermediate one and fails, but the
+ // stamp and HEAD endpoints are usually local. With ancestry proven, a
+ // differing endpoint diff means the renderer predates runtime changes.
+ // Exit 1 = differ; anything else (a stamp tree that is missing too) is
+ // still unknowable.
+ const diff = await runGit(['diff', '--quiet', stamp.commit, 'HEAD', '--', ...RUNTIME_PATHS], options)
+
+ return diff.code === 1 ? { desktopCommitsBehind: null, outOfSync: true } : NOT_STALE
}
const count = Number.parseInt(result.stdout.trim(), 10)