mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 05:32:44 +00:00
fix(desktop): apply APT architecture modifiers to explicit source restrictions (#12573)
* fix(desktop): apply APT architecture modifiers to explicit source restrictions * fix(desktop): export architecture-independent APT packages --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
1 parent
cddaef83ae
commit
184ed690d6
6 files changed
+109
-10
No files matched your search
@@ -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(
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<string, ExportAptSource>();
|
||||
const keyFiles = new Map<string, string>();
|
||||
@@ -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({
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
);
|
||||
@@ -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, string>,
|
||||
): 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(/(?<!\/)\/$/u, "");
|
||||
@@ -132,7 +145,7 @@ const stanza = (
|
||||
}),
|
||||
suites: fields.suites,
|
||||
components: fields.components,
|
||||
architectures: optionValues(fields.options.get("arch")),
|
||||
architectures: sourceArchitectures(fields.options),
|
||||
signedBy: inlineKey === null ? optionValues(signedBy) : [],
|
||||
inlineKey,
|
||||
};
|
||||
@@ -264,6 +277,8 @@ export const parseDeb822Sources = (
|
||||
options: new Map([
|
||||
["signed-by", fields.get("signed-by") ?? ""],
|
||||
["arch", fields.get("architectures") ?? ""],
|
||||
["arch+", fields.get("architectures-add") ?? ""],
|
||||
["arch-", fields.get("architectures-remove") ?? ""],
|
||||
]),
|
||||
},
|
||||
),
|
||||
|
||||
@@ -200,7 +200,7 @@ const aptRepositorySchema = z.strictObject({
|
||||
suite: z.string().nullable(),
|
||||
/** Empty for a flat repository. */
|
||||
components: z.array(z.string()),
|
||||
/** The entry's architecture restriction; empty when it names none, absent from captures written before it was recorded. */
|
||||
/** The entry's architecture restriction. `all` allows architecture-independent packages. An empty list depends on the host's APT defaults. Older captures omit this field. */
|
||||
architectures: z.array(z.string()).optional(),
|
||||
/** The release's Suite (apt's `a=`), or else its Codename, which `<package>/<release>` selects; null when unknown, absent from captures written before it was recorded. */
|
||||
release: z.string().nullable().optional(),
|
||||
|
||||
Reference in new issue
Block a user