diff --git a/src/application/desktop/DesktopApplicationExport.test.ts b/src/application/desktop/DesktopApplicationExport.test.ts index 863cba45f5..3624b8372d 100644 --- a/src/application/desktop/DesktopApplicationExport.test.ts +++ b/src/application/desktop/DesktopApplicationExport.test.ts @@ -35,6 +35,7 @@ import type { DesktopApplicationCapture, } from "../../domain/desktop/desktopCapture.js"; import { renderBuildBundle } from "../../domain/desktop/appBuild.js"; +import { parseOneLineSources } from "../../domain/desktop/aptRepositories.js"; import { readDownloadInstall } from "./DesktopExportInstall.js"; import { exportDesktopApplication } from "./DesktopApplicationExport.js"; import { @@ -1585,6 +1586,43 @@ describe("exportDesktopApplication of a program in another package", () => { }); }); +it("exports APT's architecture-independent package after all explicit architectures were removed", async () => { + const [entry] = parseOneLineSources( + "deb [arch=arm64 arch-=arm64] https://downloads.typora.io/linux ./", + "vendor.list", + ); + if (entry === undefined) throw new Error("APT source did not parse"); + expect(entry.architectures).toEqual(["all"]); + const recorded = vendorCapture(VERIFIED_KEY); + const installed = recorded.application.package; + const repositories = installed.apt_repositories?.map((repository) => ({ + ...repository, + architectures: [...entry.architectures], + })); + const exportFor = (architecture: string) => + exportVendorCapture({ + ...recorded, + application: { + ...recorded.application, + package: { ...installed, architecture, apt_repositories: repositories }, + }, + }); + + const admitted = await exportFor("all"); + if (admitted.result instanceof Error) throw admitted.result; + expect( + await readFile( + join(admitted.directory, "envs/typora/typora_app.py"), + "utf8", + ), + ).toContain('AptSource(apt="https://downloads.typora.io/linux"'); + + const refused = await exportFor("arm64"); + expect(refused.result).toMatchObject({ _tag: "AnalysisInputError" }); + expect(JSON.stringify(refused.result)).toContain("it serves only all"); + expect(await exists(refused.directory)).toBe(false); +}); + describe("exportDesktopApplication from a vendor repository", () => { it("copies the verified key, declares the repository and library packages, and turns the sandbox off", async () => { const { result, directory } = await exportVendorCapture( diff --git a/src/desktop/AptRepositoryInventory.test.ts b/src/desktop/AptRepositoryInventory.test.ts index d958dd9331..aaa980e714 100644 --- a/src/desktop/AptRepositoryInventory.test.ts +++ b/src/desktop/AptRepositoryInventory.test.ts @@ -46,8 +46,8 @@ describe.skipIf( await writeFile( sources, format === "list" - ? `deb [arch=amd64,arm64 signed-by=${key}] ${declaredUris[0]} stable,updates main,extra contrib\n` - : `Types: deb\nURIs: ${declaredUris.join("/\n ")}/\nSuites: stable,updates\nComponents: main,extra contrib\nArchitectures: amd64 arm64\nSigned-By: ${key}\n`, + ? `deb [arch=amd64,arm64 arch+=i386 arch-=arm64 signed-by=${key}] ${declaredUris[0]} stable,updates main,extra contrib\n` + : `Types: deb\nURIs: ${declaredUris.join("/\n ")}/\nSuites: stable,updates\nComponents: main,extra contrib\nArchitectures: amd64 arm64\nArchitectures-Add: i386\nArchitectures-Remove: arm64\nSigned-By: ${key}\n`, ); // No update, download or package installation: APT only describes the // configured targets, with source and state paths confined to this root. @@ -81,6 +81,13 @@ describe.skipIf( if (typeof output !== "object" || output.exitCode !== 0) throw new Error(`APT target query failed: ${JSON.stringify(output)}`); const targets = parseAptIndexTargets(output.stdout); + const descriptions = targets.map((target) => target.description); + expect(descriptions).toContainEqual( + expect.stringMatching(/ i386 Packages$/u), + ); + expect(descriptions).not.toContainEqual( + expect.stringMatching(/ arm64 Packages$/u), + ); const selected = targets.filter( (target) => target.component === "main,extra" && @@ -109,7 +116,7 @@ describe.skipIf( uri_credentials_removed: uri === uris[0], suite: "stable,updates", components: ["main,extra", "contrib"], - architectures: ["amd64", "arm64"], + architectures: ["amd64", "i386"], signing_key: expect.objectContaining({ path: key, fingerprint: VENDOR_A.fingerprint, diff --git a/src/domain/desktop/appExportInstall.ts b/src/domain/desktop/appExportInstall.ts index 091262feb5..4ba51e31cc 100644 --- a/src/domain/desktop/appExportInstall.ts +++ b/src/domain/desktop/appExportInstall.ts @@ -150,16 +150,19 @@ export const repositoryRefusal = ( }; /** - * Why a repository's architecture restriction leaves out the host's. A - * capture written before restrictions were recorded counts as unrestricted: - * apt listed the installed version from it on that host. + * Why the source cannot replay the package captured on this host. An absent + * restriction leaves the decision to APT, which listed the installed version + * from this source on the capture host. */ const architectureRefusal = ( repository: AptRepository, architecture: string, + packageArchitecture: string | null, ): string | undefined => { const served = repository.architectures ?? []; - return served.length === 0 || served.includes(architecture) + return served.length === 0 || + served.includes(architecture) || + (packageArchitecture === "all" && served.includes("all")) ? undefined : `it serves only ${served.join(", ")}, not the capture host's ${architecture}`; }; @@ -173,6 +176,7 @@ const declaredSources = ( repositories: readonly AptRepository[], environment: string, architecture: string, + packageArchitecture: string | null, ) => { const declared = new Map(); const keyFiles = new Map(); @@ -182,7 +186,7 @@ const declaredSources = ( const { suite, components, signing_key: key } = repository; const replay = repositoryReplay(repository); const reason = replay.ok - ? architectureRefusal(repository, architecture) + ? architectureRefusal(repository, architecture, packageArchitecture) : replay.error; if (!replay.ok || reason !== undefined || key === null || suite === null) { refused.push(`${describe(repository)}: ${reason ?? "it is unusable"}`); @@ -305,6 +309,7 @@ const vendorInstall = ( repositories, environment, architecture, + installed.architecture, ); if (sources.length === 0) return err({ diff --git a/src/domain/desktop/aptRepositories.test.ts b/src/domain/desktop/aptRepositories.test.ts index f18c61a51b..f7f4a462c4 100644 --- a/src/domain/desktop/aptRepositories.test.ts +++ b/src/domain/desktop/aptRepositories.test.ts @@ -769,3 +769,37 @@ it("keeps APT's source positions when a false Enabled field disables a stanza", enabled.map((_, index) => disabled.length + index + 1), ); }); + +it.each([ + ["amd64 arm64", "i386 amd64", "arm64", ["amd64", "i386"]], + ["amd64", "arm64 i386 i386", "arm64", ["amd64", "i386"]], + ["amd64", "", "amd64", ["all"]], + ["", "i386", "arm64", []], +] as const)( + "reads the explicit architecture list %s with additions %s and removals %s", + (base, add, remove, expected) => { + const fields = [ + "Types: deb", + "URIs: file:/repo", + "Suites: stable", + "Components: main", + ...(base ? [`Architectures: ${base}`] : []), + ...(add ? [`Architectures-Add: ${add}`] : []), + `Architectures-Remove: ${remove}`, + ]; + const options = [ + ...(base ? [`arch=${base.replaceAll(" ", ",")}`] : []), + `arch-=${remove}`, + ...(add ? [`arch+=${add.replaceAll(" ", ",")}`] : []), + ]; + expect( + parseDeb822Sources(fields.join("\n"), "vendor.sources")[0]?.architectures, + ).toEqual(expected); + expect( + parseOneLineSources( + `deb [${options.join(" ")}] file:/repo stable main`, + "vendor.list", + )[0]?.architectures, + ).toEqual(expected); + }, +); diff --git a/src/domain/desktop/aptRepositories.ts b/src/domain/desktop/aptRepositories.ts index 5ed451972c..228af39c60 100644 --- a/src/domain/desktop/aptRepositories.ts +++ b/src/domain/desktop/aptRepositories.ts @@ -52,6 +52,19 @@ const fieldValues = (value: string | undefined): readonly string[] => const optionValues = (value: string | undefined): readonly string[] => (value ?? "").split(/[\s,]+/u).filter((part) => part.length > 0); +/** Resolve an explicit list. Modifier-only entries depend on APT's host defaults. */ +const sourceArchitectures = ( + options: ReadonlyMap, +): string[] => { + const base = optionValues(options.get("arch")); + if (base.length === 0) return []; + const selected = new Set([...base, ...optionValues(options.get("arch+"))]); + for (const removed of optionValues(options.get("arch-"))) + selected.delete(removed); + // APT still selects architecture-independent packages when all named targets were removed. + return selected.size === 0 ? ["all"] : [...selected]; +}; + /** Keep redundant path separators that APT preserves in Repo-URI. */ const withoutOptionalTrailingSlash = (uri: string): string => uri.replace(/(?/` selects; null when unknown, absent from captures written before it was recorded. */ release: z.string().nullable().optional(),