From 6bf8340a8a486788aadbfb313adb45ac8f61f577 Mon Sep 17 00:00:00 2001 From: hided62 Date: Tue, 11 Aug 2026 00:00:02 +0000 Subject: [PATCH] fix(release): fetch remote commit before self-upgrade --- .../src/orchestrator/workspaceManager.ts | 23 +++++++++++++++---- app/gateway-api/test/workspaceManager.test.ts | 17 ++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/app/gateway-api/src/orchestrator/workspaceManager.ts b/app/gateway-api/src/orchestrator/workspaceManager.ts index 931bb1ca..be1fc191 100644 --- a/app/gateway-api/src/orchestrator/workspaceManager.ts +++ b/app/gateway-api/src/orchestrator/workspaceManager.ts @@ -77,12 +77,25 @@ export class GitWorkspaceManager { sourceMode === 'BRANCH' ? [`refs/remotes/origin/${ref}^{commit}`, `refs/heads/${ref}^{commit}`] : [`${ref}^{commit}`]; - for (const candidate of candidates) { - const result = await runGit(['rev-parse', '--verify', candidate], this.repoRoot, this.baseEnv); - const commitSha = result.output.trim().split('\n')[0]; - if (result.ok && /^[0-9a-f]{40}$/i.test(commitSha)) { - return commitSha; + const resolveCandidates = async (): Promise => { + for (const candidate of candidates) { + const result = await runGit(['rev-parse', '--verify', candidate], this.repoRoot, this.baseEnv); + const commitSha = result.output.trim().split('\n')[0]; + if (result.ok && /^[0-9a-f]{40}$/i.test(commitSha)) { + return commitSha; + } } + return undefined; + }; + const localCommit = await resolveCandidates(); + if (localCommit) return localCommit; + if (sourceMode === 'COMMIT') { + const fetched = await runGit(['fetch', '--all', '--tags'], this.repoRoot, this.baseEnv); + if (!fetched.ok) { + throw new Error(fetched.output || 'Failed to fetch git commits.'); + } + const fetchedCommit = await resolveCandidates(); + if (fetchedCommit) return fetchedCommit; } throw new Error(`${sourceMode === 'BRANCH' ? 'Branch' : 'Commit'} not found.`); } diff --git a/app/gateway-api/test/workspaceManager.test.ts b/app/gateway-api/test/workspaceManager.test.ts index e1a16854..bf0a50f2 100644 --- a/app/gateway-api/test/workspaceManager.test.ts +++ b/app/gateway-api/test/workspaceManager.test.ts @@ -75,6 +75,23 @@ describe('GitWorkspaceManager source resolution', () => { expect(await manager.resolveCommit('BRANCH', 'main')).toBe(secondCommit); }); + it('fetches a remote commit that is not present in the controller checkout yet', async () => { + const fixture = createRepositoryFixture(); + const manager = new GitWorkspaceManager({ + repoRoot: fixture.checkout, + worktreeRoot: fixture.worktrees, + }); + + fs.writeFileSync(path.join(fixture.source, 'version.txt'), 'remote-only\n'); + git(fixture.source, 'add', 'version.txt'); + git(fixture.source, 'commit', '-m', 'remote only'); + const remoteCommit = git(fixture.source, 'rev-parse', 'HEAD'); + git(fixture.source, 'push', 'origin', 'main'); + expect(() => git(fixture.checkout, 'cat-file', '-e', `${remoteCommit}^{commit}`)).toThrow(); + + await expect(manager.resolveCommit('COMMIT', remoteCommit)).resolves.toBe(remoteCommit); + }); + it('rejects option-like and range refs', async () => { const fixture = createRepositoryFixture(); const manager = new GitWorkspaceManager({