fix: settle sync push on multi-output codebase bundles (#12270)

* fix: settle sync push on multi-output bundles and empty schemas

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: compare an inferred schema against the stored one on push

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: drop empty-schema handling, keep the bundle digest fix

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ruben Fiszel
2026-11-06 13:19:25 +01:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 2acd51de13
commit 5e9bc42849
4 changed files with 63 additions and 6 deletions
+2 -2
View File
@@ -39,7 +39,7 @@ import {
import { generateFlowLockInternal } from "./flow_metadata.ts";
import { exts } from "../script/script.ts";
import type { SyncCodebase } from "../../utils/codebase.ts";
import { listSyncCodebases } from "../../utils/codebase.ts";
import { listSyncCodebases, sameCodebaseDigest } from "../../utils/codebase.ts";
import {
createPreviewLocalScriptReader,
resolvePreviewLocalScriptState,
@@ -106,7 +106,7 @@ async function findDivergedLocalPathScripts(
normalizeComparableContent(localScript.lock) !==
normalizeComparableContent(remoteLock)) ||
localScript.tag !== normalizeOptionalString(remoteScript.tag) ||
localScript.codebaseDigest !== normalizeOptionalString(remoteScript.codebase);
!sameCodebaseDigest(localScript.codebaseDigest, remoteScript.codebase);
if (diverged) {
changed.push(scriptPath);
+22 -4
View File
@@ -123,7 +123,11 @@ import {
} from "../../utils/git.ts";
import { Workspace } from "../workspace/workspace.ts";
import { removePathPrefix } from "../../types.ts";
import { listSyncCodebases, SyncCodebase } from "../../utils/codebase.ts";
import {
listSyncCodebases,
sameCodebaseDigest,
SyncCodebase,
} from "../../utils/codebase.ts";
import {
beginLockfileBatch,
flushLockfileBatch,
@@ -567,6 +571,17 @@ export function findCodebase(
}
}
/** Script metadata that differs only by the `.tar` a multi-output bundle adds to the
* deployed codebase digest. */
function sameScriptMetadataModuloTar(a: any, b: any): boolean {
if (!a || !b || typeof a != "object" || typeof b != "object") {
return false;
}
const { codebase: c1, ...rest1 } = a;
const { codebase: c2, ...rest2 } = b;
return sameCodebaseDigest(c1, c2) && deepEqual(rest1, rest2);
}
async function addCodebaseDigestIfRelevant(
path: string,
content: string,
@@ -2942,7 +2957,10 @@ export async function compareDynFSElement(
if (isEls1Remote === false && isWorkspaceSettingsFile(k)) {
stripUnappliedSettingsFields(after, before);
}
if (deepEqual(before, after)) {
if (
deepEqual(before, after) ||
(isScriptMetadata && sameScriptMetadataModuloTar(before, after))
) {
continue;
}
if (!ignoreCodebaseChanges) {
@@ -2956,7 +2974,7 @@ export async function compareDynFSElement(
delete after.codebase;
v = yamlStringify(after, yamlOptions);
}
if (beforeCodebase != afterCodebase) {
if (!sameCodebaseDigest(beforeCodebase, afterCodebase)) {
codebaseChanges[k] = afterCodebase ?? beforeCodebase ?? "";
}
}
@@ -3008,7 +3026,7 @@ export async function compareDynFSElement(
continue;
}
const c = findCodebase(tsFile, codebases);
if ((await c?.getDigest()) != v) {
if (!sameCodebaseDigest(await c?.getDigest(), v)) {
changes.push({
name: "edited",
path: tsFile,
+14
View File
@@ -43,6 +43,20 @@ export function uncoveredBundleInputs(
export type SyncCodebase = Codebase & {
getDigest: (forceTar?: boolean) => Promise<string>;
};
/** Whether two codebase digests name the same bundle. A push adds `.tar` when esbuild emits
* more than one output file, which only bundling reveals, so a diff computing `getDigest()`
* must accept the deployed digest with that suffix. The layout follows from the sources and
* the codebase config, both already in the digest. */
export function sameCodebaseDigest(
a: string | null | undefined,
b: string | null | undefined
): boolean {
const base = (d: string | null | undefined) =>
d ? (d.endsWith(".tar") ? d.slice(0, -4) : d) : undefined;
return base(a) === base(b);
}
export function listSyncCodebases(options: SyncOptions): SyncCodebase[] {
const res: SyncCodebase[] = [];
const nb_codebase = options?.codebases?.length ?? 0;
@@ -495,3 +495,28 @@ test("push: an unchanged custom_path is not sent", () => {
expect(changedCustomPath("", { custom_path: "my-dashboard" })).toBe("");
expect(changedCustomPath("new", undefined)).toBe("new");
});
const SCRIPT_META = (extra: string) =>
`summary: s\ndescription: ''\nlock: ''\nkind: script\n${extra}`;
const EXPANDED_EMPTY_SCHEMA =
"schema:\n $schema: https://json-schema.org/draft/2020-12/schema\n type: object\n properties: {}\n required: []\n";
test("push: a multi-output bundle's `.tar` digest matches the local codebase digest", async () => {
const remote = local({
"f/c/multi.script.yaml": SCRIPT_META(`codebase: abc123.tar\n${EXPANDED_EMPTY_SCHEMA}`),
});
expect(
await diff(
local({ "f/c/multi.script.yaml": SCRIPT_META(`codebase: abc123\n${EXPANDED_EMPTY_SCHEMA}`) }),
remote,
{},
),
).toEqual([]);
expect(
await diff(
local({ "f/c/multi.script.yaml": SCRIPT_META(`codebase: def456\n${EXPANDED_EMPTY_SCHEMA}`) }),
remote,
{},
),
).toEqual(["edited f/c/multi.script.yaml"]);
});