

























@@ -598,6 +598,101 @@ describe("runGatewayUpdate", () => {
598598);
599599});
600600601+it("rolls back when upstream setup fails after creating local main", async () => {
602+await setupGitPackageManagerFixture();
603+604+const selectedSha = "upstream123";
605+const calls: string[] = [];
606+const beforeGitMutation = vi.fn(async () => {
607+calls.push("beforeGitMutation");
608+});
609+const runCommand = async (argv: string[]) => {
610+const key = argv.join(" ");
611+calls.push(key);
612+const responses = buildGitWorktreeProbeResponses({ branch: "feature" });
613+const response = responses[key];
614+if (response) {
615+return toCommandResult(response);
616+}
617+if (key === `git -C ${tempDir} fetch --all --prune --no-tags`) {
618+return { stdout: "", stderr: "", code: 0 };
619+}
620+if (key === `git -C ${tempDir} rev-parse --abbrev-ref --symbolic-full-name main@{upstream}`) {
621+return {
622+stdout: "",
623+stderr: "no upstream configured for branch 'main'",
624+code: 1,
625+};
626+}
627+if (key === `git -C ${tempDir} remote`) {
628+return { stdout: "origin\n", stderr: "", code: 0 };
629+}
630+if (key === `git -C ${tempDir} rev-parse refs/remotes/origin/main`) {
631+return { stdout: selectedSha, stderr: "", code: 0 };
632+}
633+if (key === `git -C ${tempDir} rev-list --max-count=10 ${selectedSha}`) {
634+return { stdout: `${selectedSha}\n`, stderr: "", code: 0 };
635+}
636+if (
637+key.startsWith(`git -C ${tempDir} worktree add --detach /tmp/`) &&
638+key.endsWith(` ${selectedSha}`) &&
639+preflightPrefixPattern.test(key)
640+) {
641+await writePreflightPackageManagerFixtureFromWorktreeAdd(key);
642+return { stdout: `HEAD is now at ${selectedSha}`, stderr: "", code: 0 };
643+}
644+if (
645+key.startsWith("git -C /tmp/") &&
646+preflightPrefixPattern.test(key) &&
647+key.includes(" checkout --detach ") &&
648+key.endsWith(selectedSha)
649+) {
650+return { stdout: "", stderr: "", code: 0 };
651+}
652+if (key === "pnpm --version") {
653+return { stdout: "10.0.0", stderr: "", code: 0 };
654+}
655+if (key === "pnpm install" || key === "pnpm build" || key === "pnpm ui:build") {
656+return { stdout: "", stderr: "", code: 0 };
657+}
658+if (
659+key.startsWith(`git -C ${tempDir} worktree remove --force /tmp/`) &&
660+preflightPrefixPattern.test(key)
661+) {
662+return { stdout: "", stderr: "", code: 0 };
663+}
664+if (key === `git -C ${tempDir} worktree prune`) {
665+return { stdout: "", stderr: "", code: 0 };
666+}
667+if (key === `git -C ${tempDir} show-ref --verify refs/heads/main`) {
668+return { stdout: "", stderr: "", code: 1 };
669+}
670+if (key === `git -C ${tempDir} checkout -B main ${selectedSha}`) {
671+return { stdout: "", stderr: "", code: 0 };
672+}
673+if (key === `git -C ${tempDir} branch --set-upstream-to origin/main main`) {
674+return { stdout: "", stderr: "requested upstream does not exist", code: 1 };
675+}
676+return { stdout: "", stderr: "", code: 0 };
677+};
678+679+const result = await runWithCommand(runCommand, { channel: "dev", beforeGitMutation });
680+681+expect(result.status).toBe("error");
682+expect(result.reason).toBe("checkout-failed");
683+expect(calls).toContain(`git -C ${tempDir} checkout -B main ${selectedSha}`);
684+expect(calls).toContain(`git -C ${tempDir} branch --set-upstream-to origin/main main`);
685+expect(calls).toContain(`git -C ${tempDir} reset --hard`);
686+expect(calls).toContain(`git -C ${tempDir} checkout --force feature`);
687+expect(calls).toContain(`git -C ${tempDir} reset --hard abc123`);
688+expect(calls.indexOf("beforeGitMutation")).toBeLessThan(
689+calls.indexOf(`git -C ${tempDir} checkout -B main ${selectedSha}`),
690+);
691+expect(
692+calls.indexOf(`git -C ${tempDir} branch --set-upstream-to origin/main main`),
693+).toBeLessThan(calls.indexOf(`git -C ${tempDir} reset --hard`));
694+});
695+601696it("fetches only the requested tag for explicit dev tag target refs", async () => {
602697await setupGitPackageManagerFixture();
603698const targetSha = "2222222222222222222222222222222222222222";
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。