@homeflare/alchemy 0.20.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -0
- package/dist/caddy/access-forward-auth.d.ts +56 -0
- package/dist/caddy/access-forward-auth.d.ts.map +1 -0
- package/dist/caddy/index.d.ts +6 -0
- package/dist/caddy/index.d.ts.map +1 -1
- package/dist/caddy/index.js +169 -75
- package/dist/caddy/index.js.map +10 -7
- package/dist/cloudflare/mcp-server-api.d.ts +135 -0
- package/dist/cloudflare/mcp-server-api.d.ts.map +1 -0
- package/dist/cloudflare/mcp-server-form.d.ts +116 -0
- package/dist/cloudflare/mcp-server-form.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/launchd/file-converge.d.ts +70 -0
- package/dist/launchd/file-converge.d.ts.map +1 -0
- package/dist/launchd/file-identity.d.ts +32 -0
- package/dist/launchd/file-identity.d.ts.map +1 -0
- package/dist/launchd/host-file-form.d.ts +2 -0
- package/dist/launchd/host-file-form.d.ts.map +1 -1
- package/dist/launchd/host-file-lifecycle.d.ts +11 -24
- package/dist/launchd/host-file-lifecycle.d.ts.map +1 -1
- package/dist/launchd/host-file.d.ts.map +1 -1
- package/dist/launchd/index.d.ts +2 -0
- package/dist/launchd/index.d.ts.map +1 -1
- package/dist/launchd/index.js +225 -120
- package/dist/launchd/index.js.map +13 -10
- package/dist/launchd/local-runner.d.ts.map +1 -1
- package/dist/launchd/port-claims.d.ts +31 -0
- package/dist/launchd/port-claims.d.ts.map +1 -0
- package/dist/launchd/runner.d.ts +17 -2
- package/dist/launchd/runner.d.ts.map +1 -1
- package/dist/launchd/sudo-runner.d.ts +11 -0
- package/dist/launchd/sudo-runner.d.ts.map +1 -1
- package/dist/linux/index.js.map +3 -3
- package/dist/linux/sudo-listing.d.ts +47 -0
- package/dist/linux/sudo-listing.d.ts.map +1 -0
- package/dist/proxmox/credential-literals.d.ts +1 -1
- package/dist/proxmox/credential-literals.d.ts.map +1 -1
- package/dist/proxmox/generated/pbs/nodes-node.d.ts +1 -1
- package/dist/proxmox/generated/pbs/nodes-node.d.ts.map +1 -1
- package/dist/proxmox/generated/pbs.d.ts +7 -0
- package/dist/proxmox/generated/pbs.d.ts.map +1 -1
- package/dist/proxmox/generated/pve.d.ts +7 -0
- package/dist/proxmox/generated/pve.d.ts.map +1 -1
- package/dist/proxmox/index.d.ts +1 -1
- package/dist/proxmox/index.d.ts.map +1 -1
- package/dist/proxmox/index.js +2 -2
- package/dist/proxmox/index.js.map +9 -9
- package/dist/proxmox/pbs-notification-target-form.d.ts +1 -1
- package/dist/proxmox/pbs-notification-target-form.d.ts.map +1 -1
- package/dist/proxmox/pbs-notification-target.d.ts +1 -1
- package/dist/proxmox/pbs-notification-target.d.ts.map +1 -1
- package/dist/release/archive.d.ts +11 -0
- package/dist/release/archive.d.ts.map +1 -0
- package/dist/release/binary-claim.d.ts +53 -0
- package/dist/release/binary-claim.d.ts.map +1 -0
- package/dist/release/binary-diff.d.ts +38 -0
- package/dist/release/binary-diff.d.ts.map +1 -0
- package/dist/release/binary-form.d.ts +118 -0
- package/dist/release/binary-form.d.ts.map +1 -0
- package/dist/release/binary-lifecycle.d.ts +55 -0
- package/dist/release/binary-lifecycle.d.ts.map +1 -0
- package/dist/release/binary-read.d.ts +11 -0
- package/dist/release/binary-read.d.ts.map +1 -0
- package/dist/release/binary.d.ts +68 -0
- package/dist/release/binary.d.ts.map +1 -0
- package/dist/release/catalog.d.ts +113 -0
- package/dist/release/catalog.d.ts.map +1 -0
- package/dist/release/checksums.d.ts +22 -0
- package/dist/release/checksums.d.ts.map +1 -0
- package/dist/release/declared-pins.d.ts +4 -0
- package/dist/release/declared-pins.d.ts.map +1 -0
- package/dist/release/download.d.ts +44 -0
- package/dist/release/download.d.ts.map +1 -0
- package/dist/release/fake-deploy.d.ts +48 -0
- package/dist/release/fake-deploy.d.ts.map +1 -0
- package/dist/release/fake-engine.d.ts +8 -0
- package/dist/release/fake-engine.d.ts.map +1 -0
- package/dist/release/fake-install.d.ts +39 -0
- package/dist/release/fake-install.d.ts.map +1 -0
- package/dist/release/fake-provider.d.ts +58 -0
- package/dist/release/fake-provider.d.ts.map +1 -0
- package/dist/release/fake-release.d.ts +95 -0
- package/dist/release/fake-release.d.ts.map +1 -0
- package/dist/release/index.d.ts +25 -0
- package/dist/release/index.d.ts.map +1 -0
- package/dist/release/index.js +1425 -0
- package/dist/release/index.js.map +36 -0
- package/dist/release/openbao.d.ts +35 -0
- package/dist/release/openbao.d.ts.map +1 -0
- package/dist/release/providers.d.ts +19 -0
- package/dist/release/providers.d.ts.map +1 -0
- package/dist/release/refused.d.ts +39 -0
- package/dist/release/refused.d.ts.map +1 -0
- package/dist/release/tar.d.ts +14 -0
- package/dist/release/tar.d.ts.map +1 -0
- package/dist/release/victoria.d.ts +36 -0
- package/dist/release/victoria.d.ts.map +1 -0
- package/dist/{proxmox → secrets}/write-only.d.ts.map +1 -1
- package/docs/launchd-ports.md +109 -0
- package/docs/launchd.md +5 -0
- package/docs/release-binary-catalogs.md +138 -0
- package/docs/release-binary-measured.md +163 -0
- package/docs/release-binary-openbao.md +151 -0
- package/docs/release-binary-refusals.md +57 -0
- package/docs/release-binary-upstream.md +163 -0
- package/docs/release-binary.md +165 -0
- package/package.json +5 -1
- package/src/caddy/access-forward-auth.test.ts +63 -0
- package/src/caddy/access-forward-auth.ts +120 -0
- package/src/caddy/index.ts +10 -0
- package/src/caddy/providers.test.ts +4 -0
- package/src/cloudflare/mcp-server-api.ts +294 -0
- package/src/cloudflare/mcp-server-form.ts +219 -0
- package/src/index.ts +1 -0
- package/src/launchd/file-converge.ts +233 -0
- package/src/launchd/file-identity.ts +69 -0
- package/src/launchd/host-file-alias.test.ts +65 -0
- package/src/launchd/host-file-form.ts +2 -1
- package/src/launchd/host-file-lifecycle.ts +25 -144
- package/src/launchd/host-file.ts +8 -2
- package/src/launchd/index.ts +2 -0
- package/src/launchd/local-runner.test.ts +12 -1
- package/src/launchd/local-runner.ts +2 -0
- package/src/launchd/port-claims.test.ts +124 -0
- package/src/launchd/port-claims.ts +102 -0
- package/src/launchd/providers.test.ts +3 -0
- package/src/launchd/runner.ts +17 -2
- package/src/launchd/sudo-runner.ts +11 -0
- package/src/linux/sudo-listing.ts +122 -0
- package/src/proxmox/credential-literals.ts +1 -1
- package/src/proxmox/generated/pbs/nodes-node.ts +1 -1
- package/src/proxmox/generated/pbs.ts +7 -0
- package/src/proxmox/generated/pve.ts +7 -0
- package/src/proxmox/index.ts +1 -1
- package/src/proxmox/pbs-notification-target-form.ts +1 -1
- package/src/proxmox/pbs-notification-target-lifecycle.ts +1 -1
- package/src/proxmox/pbs-notification-target-wire.ts +1 -1
- package/src/proxmox/pbs-notification-target.ts +1 -1
- package/src/release/adopt-parity.test.ts +106 -0
- package/src/release/apply-pins.test.ts +128 -0
- package/src/release/archive.ts +94 -0
- package/src/release/binary-alias.test.ts +109 -0
- package/src/release/binary-claim.ts +80 -0
- package/src/release/binary-claims.test.ts +47 -0
- package/src/release/binary-diff.ts +73 -0
- package/src/release/binary-form.ts +229 -0
- package/src/release/binary-lifecycle.test.ts +90 -0
- package/src/release/binary-lifecycle.ts +202 -0
- package/src/release/binary-read.ts +55 -0
- package/src/release/binary-refusals.test.ts +192 -0
- package/src/release/binary-sudo.test.ts +93 -0
- package/src/release/binary.ts +181 -0
- package/src/release/catalog.test.ts +167 -0
- package/src/release/catalog.ts +238 -0
- package/src/release/checksums.test.ts +35 -0
- package/src/release/checksums.ts +43 -0
- package/src/release/declared-pins.ts +39 -0
- package/src/release/download.test.ts +138 -0
- package/src/release/download.ts +110 -0
- package/src/release/error-channel.test.ts +69 -0
- package/src/release/fake-deploy.ts +87 -0
- package/src/release/fake-engine.ts +50 -0
- package/src/release/fake-install.ts +59 -0
- package/src/release/fake-provider.ts +68 -0
- package/src/release/fake-release.ts +185 -0
- package/src/release/fixtures/openbao/checksums.txt +83 -0
- package/src/release/fixtures/openbao/checksums.txt.gpgsig +0 -0
- package/src/release/fixtures/openbao/darwin-assets.txt +12 -0
- package/src/release/fixtures/openbao/openbao-gpg-pub-20240618.asc +109 -0
- package/src/release/fixtures/victoria/darwin-arm64-assets.txt +22 -0
- package/src/release/fixtures/victoria/victoria-logs-darwin-arm64-v1.52.0_checksums.txt +2 -0
- package/src/release/fixtures/victoria/victoria-metrics-darwin-arm64-v1.151.0_checksums.txt +2 -0
- package/src/release/fixtures/victoria/victoria-traces-darwin-arm64-v0.10.0_checksums.txt +2 -0
- package/src/release/fixtures/victoria/vmutils-darwin-arm64-v1.151.0_checksums.txt +8 -0
- package/src/release/index.ts +44 -0
- package/src/release/openbao.test.ts +120 -0
- package/src/release/openbao.ts +86 -0
- package/src/release/plan.test.ts +189 -0
- package/src/release/provider-refusals.test.ts +48 -0
- package/src/release/providers.test.ts +175 -0
- package/src/release/providers.ts +24 -0
- package/src/release/recovery-read.test.ts +44 -0
- package/src/release/refused.ts +40 -0
- package/src/release/tar.test.ts +142 -0
- package/src/release/tar.ts +195 -0
- package/src/release/victoria.test.ts +108 -0
- package/src/release/victoria.ts +154 -0
- package/src/{proxmox → secrets}/write-only.ts +6 -0
- /package/dist/{proxmox → secrets}/write-only.d.ts +0 -0
- /package/src/{proxmox → secrets}/write-only.test.ts +0 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ⛔ A PIN IS NEVER COMPUTED DURING THE DEPLOY — on a FIRST deploy too. Release.Binary through
|
|
3
|
+
* Alchemy's own Plan and Apply (openbao/fake-stack.ts), with a pin wired from another resource's
|
|
4
|
+
* Output: the shape of "fetch the checksum file at apply and trust what it says".
|
|
5
|
+
*
|
|
6
|
+
* 🔴 MEASURED 2026-09-22 (supply-chain review of PR 138): before the apply-time check, the engine
|
|
7
|
+
* never diffed this create and skipped its probe (an Output in `news`), so reconcile saw only the
|
|
8
|
+
* RESOLVED digests. The release asset and its checksum file were both swapped (the releases are
|
|
9
|
+
* mutable, victoria.ts), the Output carried the swapped digests, and the deploy installed the
|
|
10
|
+
* swapped bytes and reported them verified. binary-diff.ts refused the same declaration only
|
|
11
|
+
* from the SECOND plan on — after the wrong binary was already on the host.
|
|
12
|
+
*/
|
|
13
|
+
import { describe, expect, test } from 'bun:test';
|
|
14
|
+
import { Resource } from 'alchemy';
|
|
15
|
+
import * as Provider from 'alchemy/Provider';
|
|
16
|
+
import * as Effect from 'effect/Effect';
|
|
17
|
+
import * as Layer from 'effect/Layer';
|
|
18
|
+
import * as HttpClient from 'effect/unstable/http/HttpClient';
|
|
19
|
+
import * as HttpClientResponse from 'effect/unstable/http/HttpClientResponse';
|
|
20
|
+
import { sha256Hex } from '../launchd/job-form.ts';
|
|
21
|
+
import { type HostRunner, hostRunnerLayer } from '../launchd/runner.ts';
|
|
22
|
+
import { HostDirectory, HostDirectoryProvider } from '../linux/directory.ts';
|
|
23
|
+
import { fakeLinuxHost } from '../linux/fake-linux-host.ts';
|
|
24
|
+
import { fakeStack } from '../openbao/fake-stack.ts';
|
|
25
|
+
import { ReleaseBinary, makeReleaseBinaryProvider } from './binary.ts';
|
|
26
|
+
import { catalogBinary } from './catalog.ts';
|
|
27
|
+
import {
|
|
28
|
+
VMALERT_REQUEST,
|
|
29
|
+
VMUTILS_URL,
|
|
30
|
+
bytesOf,
|
|
31
|
+
gzip,
|
|
32
|
+
syntheticRelease,
|
|
33
|
+
tarOf,
|
|
34
|
+
} from './fake-release.ts';
|
|
35
|
+
|
|
36
|
+
const ROOT = '/opt/example/bin';
|
|
37
|
+
const DIR = `${ROOT}/vmutils-1.151.0`;
|
|
38
|
+
const EVIL = bytesOf('#!swapped vmalert\n');
|
|
39
|
+
const SWAPPED = gzip(tarOf([{ bytes: EVIL, name: 'vmalert-prod' }]));
|
|
40
|
+
|
|
41
|
+
/** What a stack might write to "stay current": digests read from the release at apply. */
|
|
42
|
+
type Sums = { readonly archive: string; readonly member: string; readonly size: number };
|
|
43
|
+
interface FetchedSums extends Resource<'Test.FetchedSums', { url: string }, Sums> {}
|
|
44
|
+
const FetchedSums = Resource<FetchedSums>('Test.FetchedSums');
|
|
45
|
+
/** ★ It answers with the SWAPPED asset's digests — what the swapped checksum file would say. */
|
|
46
|
+
const FetchedSumsProvider = () =>
|
|
47
|
+
Provider.effect(
|
|
48
|
+
FetchedSums,
|
|
49
|
+
Effect.succeed(
|
|
50
|
+
FetchedSums.Provider.of({
|
|
51
|
+
delete: () => Effect.void,
|
|
52
|
+
list: () => Effect.succeed([]),
|
|
53
|
+
reconcile: () =>
|
|
54
|
+
Effect.succeed({
|
|
55
|
+
archive: sha256Hex(SWAPPED),
|
|
56
|
+
member: sha256Hex(EVIL),
|
|
57
|
+
size: SWAPPED.length,
|
|
58
|
+
}),
|
|
59
|
+
}),
|
|
60
|
+
),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const harness = () => {
|
|
64
|
+
const pins = catalogBinary(syntheticRelease().catalog, VMALERT_REQUEST);
|
|
65
|
+
const fake = fakeLinuxHost({ dirs: { [ROOT]: 0 }, euid: 0 });
|
|
66
|
+
const events: string[] = [];
|
|
67
|
+
const runner: HostRunner = {
|
|
68
|
+
...fake.runner,
|
|
69
|
+
writeFileAtomic: (path, bytes, options) => {
|
|
70
|
+
events.push(`write ${path}`);
|
|
71
|
+
return fake.runner.writeFileAtomic(path, bytes, options);
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
// ★ The attacker's release: the swapped archive at the REAL asset URL.
|
|
75
|
+
const client = HttpClient.make((request, url) => {
|
|
76
|
+
events.push(`GET ${url.toString()}`);
|
|
77
|
+
const body = url.toString() === VMUTILS_URL ? new Blob([SWAPPED.slice()]) : null;
|
|
78
|
+
return Effect.succeed(
|
|
79
|
+
HttpClientResponse.fromWeb(request, new Response(body, { status: body ? 200 : 404 })),
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
const providers = Layer.mergeAll(
|
|
83
|
+
makeReleaseBinaryProvider({ download: { retries: 0 } }),
|
|
84
|
+
HostDirectoryProvider(),
|
|
85
|
+
FetchedSumsProvider(),
|
|
86
|
+
).pipe(
|
|
87
|
+
Layer.provide(
|
|
88
|
+
Layer.mergeAll(hostRunnerLayer(runner), Layer.succeed(HttpClient.HttpClient, client)),
|
|
89
|
+
),
|
|
90
|
+
);
|
|
91
|
+
return { events, fake, pins, stack: fakeStack(providers, {}, 'ApplyPinStack') };
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
type Wiring = 'every digest and the size' | 'the member digest' | 'the archive digest and size';
|
|
95
|
+
|
|
96
|
+
describe('a pin wired from an Output, on a first deploy', () => {
|
|
97
|
+
test.each<[Wiring, string]>([
|
|
98
|
+
['every digest and the size', 'archive.sha256 is required, as a plain string'],
|
|
99
|
+
['the member digest', 'sha256 is required, as a plain string'],
|
|
100
|
+
['the archive digest and size', 'archive.size must be'],
|
|
101
|
+
])('%s: refused at apply, nothing fetched, nothing written', async (wiring, refusal) => {
|
|
102
|
+
const h = harness();
|
|
103
|
+
const body = Effect.gen(function* () {
|
|
104
|
+
const dir = yield* HostDirectory('vmutils-1.151.0', { mode: 0o755, path: DIR });
|
|
105
|
+
const sums = yield* FetchedSums('sums', { url: `${VMUTILS_URL}_checksums.txt` });
|
|
106
|
+
const archive =
|
|
107
|
+
wiring === 'the member digest'
|
|
108
|
+
? h.pins.archive
|
|
109
|
+
: { ...h.pins.archive, sha256: sums.archive, size: sums.size };
|
|
110
|
+
const sha256 = wiring === 'the archive digest and size' ? h.pins.sha256 : sums.member;
|
|
111
|
+
yield* ReleaseBinary('vmalert', { ...h.pins, archive, directory: dir.path, sha256 });
|
|
112
|
+
});
|
|
113
|
+
await expect(h.stack.deploy(body)).rejects.toThrow(refusal);
|
|
114
|
+
expect(h.events).toEqual([]);
|
|
115
|
+
expect(h.fake.files.has(`${DIR}/vmalert`)).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('control: the same swap against plain pins is refused by the download it makes', async () => {
|
|
119
|
+
const h = harness();
|
|
120
|
+
const body = Effect.gen(function* () {
|
|
121
|
+
const dir = yield* HostDirectory('vmutils-1.151.0', { mode: 0o755, path: DIR });
|
|
122
|
+
yield* ReleaseBinary('vmalert', { ...h.pins, directory: dir.path });
|
|
123
|
+
});
|
|
124
|
+
await expect(h.stack.deploy(body)).rejects.toThrow('the pin says');
|
|
125
|
+
expect(h.events).toEqual([`GET ${VMUTILS_URL}`]);
|
|
126
|
+
expect(h.fake.files.has(`${DIR}/vmalert`)).toBe(false);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A pinned archive, verified, to the one member a declaration names, verified — the order the
|
|
3
|
+
* checks run in is the point of the file.
|
|
4
|
+
*
|
|
5
|
+
* 1. the archive's SHA-256 against its pin — BEFORE a single byte is unpacked;
|
|
6
|
+
* 2. gunzip and tar-read as one stream, keeping only the declared member (tar.ts refuses anything
|
|
7
|
+
* unsafe in the archive, asked-for or not);
|
|
8
|
+
* 3. that member's SHA-256 against its own pin.
|
|
9
|
+
*
|
|
10
|
+
* ★ BOTH LAYERS, BECAUSE THE VENDOR HASHES BOTH. Each checksum file lists the archive AND every
|
|
11
|
+
* binary inside it (measured 2026-09-22, all four). The archive check says the download is the
|
|
12
|
+
* published file; the member check says the bytes about to be written are the published binary —
|
|
13
|
+
* and it is the only check that still holds if the tar reader were ever wrong about a boundary.
|
|
14
|
+
* ★ DecompressionStream, THE WEB STANDARD: node and bun both ship it, so dist behaves the same
|
|
15
|
+
* under either runtime — no zlib binding, no dependency.
|
|
16
|
+
* ⛔ IN MEMORY ONLY. Nothing here touches a disk, so no failure below can leave a staged download
|
|
17
|
+
* behind; the bytes reach a host only through HostRunner.writeFileAtomic (file-converge.ts).
|
|
18
|
+
*/
|
|
19
|
+
import { sha256Hex } from '../launchd/job-form.ts';
|
|
20
|
+
import type { PinnedDownload } from './binary-form.ts';
|
|
21
|
+
import { ArchiveRefused, ChecksumMismatch } from './refused.ts';
|
|
22
|
+
import { type TarContents, tarReader } from './tar.ts';
|
|
23
|
+
|
|
24
|
+
/** How much gzip is handed to the inflater at a time. */
|
|
25
|
+
const SLICE = 1 << 20;
|
|
26
|
+
|
|
27
|
+
/** Gunzip and read a tar, keeping only `wanted`. Throws ArchiveRefused. */
|
|
28
|
+
export const extractMembers = async (
|
|
29
|
+
gzipped: Uint8Array,
|
|
30
|
+
wanted: ReadonlySet<string>,
|
|
31
|
+
): Promise<TarContents> => {
|
|
32
|
+
const tar = tarReader(wanted);
|
|
33
|
+
// ⚠️ FED IN SLICES, ON DEMAND. Enqueued whole, the 123.6 MB vmutils archive is inflated in one
|
|
34
|
+
// transform step and all 264 MB of output queue up before the first read: MEASURED 2026-09-22,
|
|
35
|
+
// a peak RSS of 1116 MB for vmalert alone under bun 1.4.0. `pull` hands over the next slice only
|
|
36
|
+
// when the stream asks, so backpressure bounds what is inflated ahead of the tar reader.
|
|
37
|
+
let offset = 0;
|
|
38
|
+
const source = new ReadableStream<Uint8Array>({
|
|
39
|
+
pull(controller) {
|
|
40
|
+
if (offset >= gzipped.length) {
|
|
41
|
+
controller.close();
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
controller.enqueue(gzipped.slice(offset, offset + SLICE));
|
|
45
|
+
offset += SLICE;
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
const unzipped = source.pipeThrough(new DecompressionStream('gzip')).getReader();
|
|
49
|
+
try {
|
|
50
|
+
for (;;) {
|
|
51
|
+
const { done, value } = await unzipped.read();
|
|
52
|
+
if (done) break;
|
|
53
|
+
tar.push(value);
|
|
54
|
+
}
|
|
55
|
+
} catch (cause) {
|
|
56
|
+
await unzipped.cancel().catch(() => undefined);
|
|
57
|
+
if (cause instanceof ArchiveRefused) throw cause;
|
|
58
|
+
throw new ArchiveRefused({ message: `not a gzip stream (${String(cause)})` });
|
|
59
|
+
}
|
|
60
|
+
return tar.finish();
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const mismatch = (subject: string, expected: string, actual: string): ChecksumMismatch =>
|
|
64
|
+
new ChecksumMismatch({
|
|
65
|
+
actual,
|
|
66
|
+
expected,
|
|
67
|
+
message: `${subject} hashes to ${actual}, not the pinned ${expected}`,
|
|
68
|
+
subject,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The declared member's bytes out of a downloaded archive, both layers checked.
|
|
73
|
+
* ⚠️ `archive` may be shared with another resource's extraction (download.ts sharingInFlight):
|
|
74
|
+
* this only reads it.
|
|
75
|
+
*/
|
|
76
|
+
export const verifiedMember = async (
|
|
77
|
+
archive: Uint8Array,
|
|
78
|
+
release: PinnedDownload,
|
|
79
|
+
): Promise<Uint8Array> => {
|
|
80
|
+
const archiveSha = sha256Hex(archive);
|
|
81
|
+
if (archiveSha !== release.sha256) throw mismatch(release.url, release.sha256, archiveSha);
|
|
82
|
+
const { members, names } = await extractMembers(archive, new Set([release.member]));
|
|
83
|
+
const bytes = members.get(release.member);
|
|
84
|
+
if (bytes === undefined) {
|
|
85
|
+
throw new ArchiveRefused({
|
|
86
|
+
message: `${release.url} has no member named exactly "${release.member}" (it has ${names.map((n) => `"${n}"`).join(', ') || 'none'})`,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
const memberSha = sha256Hex(bytes);
|
|
90
|
+
if (memberSha !== release.memberSha256) {
|
|
91
|
+
throw mismatch(`member "${release.member}"`, release.memberSha256, memberSha);
|
|
92
|
+
}
|
|
93
|
+
return bytes;
|
|
94
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ONE FILE UNDER TWO SPELLINGS (launchd/file-identity.ts), on a REAL filesystem: localRunner in a
|
|
3
|
+
* fresh temp directory, through Alchemy's own Plan and Apply where the engine's order matters.
|
|
4
|
+
* Nothing outside `mkdtemp` is touched, and the release is synthetic (fake-release.ts).
|
|
5
|
+
*
|
|
6
|
+
* 🔴 EACH TEST BELOW FAILED BEFORE THE FIX (measured 2026-09-22): the respelled deploy planned a
|
|
7
|
+
* `replace`, reported success, and left no binary on disk; the next deploy put it back.
|
|
8
|
+
*/
|
|
9
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
10
|
+
import { mkdir, mkdtemp, rm, stat, symlink } from 'node:fs/promises';
|
|
11
|
+
import { tmpdir } from 'node:os';
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
import { type HostRunner } from '../launchd/runner.ts';
|
|
14
|
+
import { localRunner } from '../launchd/local-runner.ts';
|
|
15
|
+
import { reconcileBinary } from './binary-lifecycle.ts';
|
|
16
|
+
import { VMALERT_TEXT, realEngine } from './fake-engine.ts';
|
|
17
|
+
import { VMUTILS_URL, fakeTransport, syntheticRelease, vmalertProps } from './fake-release.ts';
|
|
18
|
+
|
|
19
|
+
let tmp = '';
|
|
20
|
+
beforeEach(async () => {
|
|
21
|
+
tmp = await mkdtemp(join(tmpdir(), 'hf-alias-'));
|
|
22
|
+
await mkdir(join(tmp, 'real', 'vmutils-1.151.0'), { recursive: true });
|
|
23
|
+
await symlink(join(tmp, 'real'), join(tmp, 'link'));
|
|
24
|
+
});
|
|
25
|
+
afterEach(async () => {
|
|
26
|
+
await rm(tmp, { force: true, recursive: true });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const REAL = () => join(tmp, 'real', 'vmutils-1.151.0');
|
|
30
|
+
const LINKED = () => join(tmp, 'link', 'vmutils-1.151.0');
|
|
31
|
+
/** The installed binary's text, or undefined when the deploy lost it. */
|
|
32
|
+
const onDisk = () =>
|
|
33
|
+
Bun.file(join(REAL(), 'vmalert'))
|
|
34
|
+
.text()
|
|
35
|
+
.catch(() => undefined);
|
|
36
|
+
const engine = () => {
|
|
37
|
+
const e = realEngine();
|
|
38
|
+
return { deploy: (directory: string) => e.deploy({ vmalert: directory }), gets: e.gets };
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** Whether this temp directory's volume folds case (APFS's default on macOS; not ext4). */
|
|
42
|
+
const foldsCase = async (): Promise<boolean> =>
|
|
43
|
+
stat(join(tmp, 'REAL')).then(
|
|
44
|
+
() => true,
|
|
45
|
+
() => false,
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
describe('a respelled directory is an update that keeps the file, never a replace', () => {
|
|
49
|
+
test('through a symlinked parent, via the engine', async () => {
|
|
50
|
+
const e = engine();
|
|
51
|
+
expect(await e.deploy(REAL())).toEqual({ vmalert: 'create' });
|
|
52
|
+
expect(await e.deploy(LINKED())).toEqual({ vmalert: 'update' });
|
|
53
|
+
expect(await onDisk()).toBe(VMALERT_TEXT);
|
|
54
|
+
expect(await e.deploy(LINKED())).toEqual({ vmalert: 'noop' });
|
|
55
|
+
expect(e.gets).toEqual([VMUTILS_URL]);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('by case alone, on a volume that folds case', async () => {
|
|
59
|
+
if (!(await foldsCase())) return;
|
|
60
|
+
const e = engine();
|
|
61
|
+
await e.deploy(REAL());
|
|
62
|
+
expect(await e.deploy(join(tmp, 'real', 'VMUTILS-1.151.0'))).toEqual({ vmalert: 'update' });
|
|
63
|
+
expect(await onDisk()).toBe(VMALERT_TEXT);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('an update across the respelling (the path unresolved at plan) keeps the file', async () => {
|
|
67
|
+
const { catalog, vmutils } = syntheticRelease();
|
|
68
|
+
const fetch = fakeTransport({ [VMUTILS_URL]: vmutils }).fetch;
|
|
69
|
+
const olds = vmalertProps(catalog, { directory: REAL() });
|
|
70
|
+
const output = await reconcileBinary(localRunner(), fetch, olds);
|
|
71
|
+
const news = vmalertProps(catalog, { directory: LINKED() });
|
|
72
|
+
const after = await reconcileBinary(localRunner(), fetch, news, { olds, output });
|
|
73
|
+
expect(after.path).toBe(join(LINKED(), 'vmalert'));
|
|
74
|
+
expect(await onDisk()).toBe(VMALERT_TEXT);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('⛔ other bytes at the respelled path are still refused, never written in place', async () => {
|
|
78
|
+
const { catalog, vmutils } = syntheticRelease();
|
|
79
|
+
const transport = fakeTransport({ [VMUTILS_URL]: vmutils });
|
|
80
|
+
const olds = vmalertProps(catalog, { directory: REAL() });
|
|
81
|
+
const output = await reconcileBinary(localRunner(), transport.fetch, olds);
|
|
82
|
+
const news = vmalertProps(catalog, { directory: LINKED(), sha256: 'e'.repeat(64) });
|
|
83
|
+
await expect(
|
|
84
|
+
reconcileBinary(localRunner(), transport.fetch, news, { olds, output }),
|
|
85
|
+
).rejects.toThrow('already exists and is not this resource');
|
|
86
|
+
expect(await onDisk()).toBe(VMALERT_TEXT);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('⚠️ a runner that reports no identity: the loss fails the deploy instead of passing', async () => {
|
|
90
|
+
const real = localRunner();
|
|
91
|
+
const blind: HostRunner = {
|
|
92
|
+
...real,
|
|
93
|
+
stat: async (path) => {
|
|
94
|
+
const found = await real.stat(path);
|
|
95
|
+
if (found === undefined) return undefined;
|
|
96
|
+
const { dev: _dev, ino: _ino, ...rest } = found;
|
|
97
|
+
return rest;
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
const { catalog, vmutils } = syntheticRelease();
|
|
101
|
+
const fetch = fakeTransport({ [VMUTILS_URL]: vmutils }).fetch;
|
|
102
|
+
const olds = vmalertProps(catalog, { directory: REAL() });
|
|
103
|
+
const output = await reconcileBinary(blind, fetch, olds);
|
|
104
|
+
const news = vmalertProps(catalog, { directory: LINKED() });
|
|
105
|
+
await expect(reconcileBinary(blind, fetch, news, { olds, output })).rejects.toThrow(
|
|
106
|
+
'they are one file under two spellings',
|
|
107
|
+
);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a Release.Binary may take over at a path it holds no state for: ONLY the pinned binary, and
|
|
3
|
+
* only under `--adopt`. Asked the same way at plan (binary-diff.ts) and at apply
|
|
4
|
+
* (binary-lifecycle.ts), so a plan never says `adopted` or `create` for a file the apply would then
|
|
5
|
+
* overwrite or silently claim.
|
|
6
|
+
*
|
|
7
|
+
* ⛔ OTHER BYTES ARE NEVER ADOPTED, `--adopt` OR NOT. 🔴 MEASURED 2026-09-22 (adopt-parity.test.ts,
|
|
8
|
+
* through Alchemy's own Plan and Apply): under `--adopt`, a file with other bytes at the path
|
|
9
|
+
* planned as `adopted` — beta.79 forces an `adopted` update after every takeover and prints it for
|
|
10
|
+
* drift too — and the apply downloaded the archive and overwrote that file in place. With the
|
|
11
|
+
* directory an Output (the probe skipped) the same file planned as `create`, and was overwritten.
|
|
12
|
+
* ★ Refused rather than converged, which is what Host.File does with a file it adopts: a binary's
|
|
13
|
+
* content is named entirely by its pin, so "adopting" other bytes is replacing them under
|
|
14
|
+
* whatever runs them, with no rollback but a re-download — the very overwrite binary-form.ts
|
|
15
|
+
* inPlaceRefusal refuses for a re-pin. The pinned bytes with another mode or owner ARE adopted;
|
|
16
|
+
* the apply re-writes the bytes already on disk.
|
|
17
|
+
* ⛔ THE PINNED BYTES WITH NO STATE ARE NOT OURS WITHOUT `--adopt` — AT APPLY AS AT PLAN. The probe
|
|
18
|
+
* already says `Unowned` for them (docs/ownership.md: identical is not ours). file-converge.ts
|
|
19
|
+
* accepts them at apply as the resume of an interrupted install, and that gap is where the probe
|
|
20
|
+
* never runs: every first deploy that passes `directory: dir.path`. 🔴 MEASURED 2026-09-22: a
|
|
21
|
+
* declaration renamed (a new logical id, the same path) in a deploy that also changed its
|
|
22
|
+
* HostDirectory's mode claimed the identical file at apply without `--adopt`; the orphan delete of
|
|
23
|
+
* the old name then removed it, and the deploy reported success with the binary gone. With the
|
|
24
|
+
* directory unchanged, the probe refused that same rename.
|
|
25
|
+
* ⚠️ THE COST: an install interrupted between its write and its commit while a prop was an
|
|
26
|
+
* Output now resumes only with `--adopt` — as the same install with every prop resolved already
|
|
27
|
+
* did (its recovery read is `Unowned`), and as ownership.md says a create or replace interrupted
|
|
28
|
+
* while a prop was an Output does. A retained old version is not re-claimed by a rollback either.
|
|
29
|
+
* ★ `renamedFrom()` IS THE REMEDY FOR A RENAME: `.pipe(renamedFrom('old-id'))` migrates the row
|
|
30
|
+
* and keeps the file (adopt-parity.test.ts). 🔴 MEASURED 2026-09-22: the same rename under
|
|
31
|
+
* `--adopt` claimed the file, the old name's delete then removed it, and the deploy succeeded
|
|
32
|
+
* with the binary gone. binary.ts's delete now leaves a path another declaration installed in
|
|
33
|
+
* the same deploy, so that is kept too — as an adoption, not as the old row. ⚠️ That guard sees
|
|
34
|
+
* only this deploy's claims, by spelling; nothing here sees another row's claim in state.
|
|
35
|
+
* ★ HOW DIFF TELLS A TAKEOVER FROM ITS OWN ROW. Every row this resource commits records the digest
|
|
36
|
+
* reconcile READ BACK, which it checked equal to the pin — so `output.sha256 === olds.sha256` for
|
|
37
|
+
* every row of its own, and an update never changes the digest (a new digest is a new path, a
|
|
38
|
+
* `replace`). The engine hands diff anything else only after a read of a path it holds no state
|
|
39
|
+
* for: the adoption probe (`olds` = the declaration) or the recovery read of an interrupted
|
|
40
|
+
* create (`olds` = its row). A non-file reads with digest '' (file-converge.ts).
|
|
41
|
+
*/
|
|
42
|
+
import { type FileTarget, readFileAttributes } from '../launchd/file-converge.ts';
|
|
43
|
+
import type { HostRunner } from '../launchd/runner.ts';
|
|
44
|
+
|
|
45
|
+
const TAKEN = 'already exists and is not this resource';
|
|
46
|
+
|
|
47
|
+
const otherBytes = (found: string, pinned: string): string =>
|
|
48
|
+
`${found === '' ? 'something that is not a regular file' : `a file hashing to ${found}`} is ` +
|
|
49
|
+
`there, not the pinned binary (${pinned}). --adopt takes over only the pinned binary: taking ` +
|
|
50
|
+
'over other bytes would overwrite them in place. Remove it (or move it aside) and deploy again';
|
|
51
|
+
|
|
52
|
+
/** Plan side: why diff must refuse `found` — a digest read at a path with no state — or undefined. */
|
|
53
|
+
export const adoptionProblem = (found: string, pinned: string): string | undefined =>
|
|
54
|
+
found === pinned ? undefined : `${TAKEN}: ${otherBytes(found, pinned)}`;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Apply side, for a reconcile with no `output` — a create, a replace's new generation, or the
|
|
58
|
+
* resume of either: why it must not write, or undefined. `adopt` is adoptsAtApply's answer (never
|
|
59
|
+
* true for a fresh replace). A symlink or directory is left to convergeFile, which refuses it by
|
|
60
|
+
* kind.
|
|
61
|
+
*/
|
|
62
|
+
export const claimProblem = async (
|
|
63
|
+
runner: HostRunner,
|
|
64
|
+
want: FileTarget,
|
|
65
|
+
adopt: boolean,
|
|
66
|
+
): Promise<string | undefined> => {
|
|
67
|
+
const stat = await runner.stat(want.path);
|
|
68
|
+
if (stat?.kind !== 'file') return undefined;
|
|
69
|
+
const found = (await readFileAttributes(runner, want.path))?.sha256 ?? '';
|
|
70
|
+
if (found !== want.sha256) return adoptionProblem(found, want.sha256);
|
|
71
|
+
if (adopt) return undefined;
|
|
72
|
+
return (
|
|
73
|
+
`${TAKEN}: it holds the pinned binary, but this stack holds no state for it and the plan ` +
|
|
74
|
+
'could not ask first (a prop was still an Output, or a replace landed on it). ' +
|
|
75
|
+
'Identical is not ours: once claimed, a later delete removes it from whoever put it there. ' +
|
|
76
|
+
'Deploy with --adopt to take it over (a create, or an interrupted install of this one), or ' +
|
|
77
|
+
'remove it. If another declaration in this stack owned it under another name, declare the ' +
|
|
78
|
+
'rename with renamedFrom() instead'
|
|
79
|
+
);
|
|
80
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ONE PATH, ONE DECLARATION (binary.ts `claim`), through Alchemy's own Plan and Apply over the real
|
|
3
|
+
* localRunner in a fresh temp directory (fake-engine.ts).
|
|
4
|
+
*
|
|
5
|
+
* 🔴 MEASURED 2026-09-22 BEFORE THE FIX: `vmalert` and `vmalert-logs` declared at one path both
|
|
6
|
+
* planned `create` and both succeeded; the next deploy, without `vmalert-logs`, planned
|
|
7
|
+
* `vmalert: noop, vmalert-logs: delete` — and the file `vmalert` still declared was gone.
|
|
8
|
+
*/
|
|
9
|
+
import { afterEach, beforeEach, expect, test } from 'bun:test';
|
|
10
|
+
import { mkdir, mkdtemp, rm } from 'node:fs/promises';
|
|
11
|
+
import { tmpdir } from 'node:os';
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
import { VMALERT_TEXT, realEngine } from './fake-engine.ts';
|
|
14
|
+
import { VMUTILS_URL } from './fake-release.ts';
|
|
15
|
+
|
|
16
|
+
let dir = '';
|
|
17
|
+
beforeEach(async () => {
|
|
18
|
+
dir = join(await mkdtemp(join(tmpdir(), 'hf-claims-')), 'vmutils-1.151.0');
|
|
19
|
+
await mkdir(dir);
|
|
20
|
+
});
|
|
21
|
+
afterEach(async () => {
|
|
22
|
+
await rm(join(dir, '..'), { force: true, recursive: true });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const onDisk = () =>
|
|
26
|
+
Bun.file(join(dir, 'vmalert'))
|
|
27
|
+
.text()
|
|
28
|
+
.catch(() => undefined);
|
|
29
|
+
|
|
30
|
+
test('⛔ a second resource at the same path is refused in the deploy that declares it', async () => {
|
|
31
|
+
const e = realEngine();
|
|
32
|
+
await expect(e.deploy({ vmalert: dir, 'vmalert-logs': dir })).rejects.toThrow(
|
|
33
|
+
'is already installed by',
|
|
34
|
+
);
|
|
35
|
+
// One of the two installed it; the other touched nothing.
|
|
36
|
+
expect(await onDisk()).toBe(VMALERT_TEXT);
|
|
37
|
+
expect(e.gets).toEqual([VMUTILS_URL]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('declared once, the survivor keeps its file when the stack is corrected', async () => {
|
|
41
|
+
const e = realEngine();
|
|
42
|
+
await e.deploy({ vmalert: dir, 'vmalert-logs': dir }).catch(() => undefined);
|
|
43
|
+
// ★ MEASURED: the first declared won the claim. The refused one left only the engine's
|
|
44
|
+
// unfinished-create row, whose delete touches no file — so the survivor keeps its binary.
|
|
45
|
+
expect(await e.deploy({ vmalert: dir })).toEqual({ vmalert: 'noop', 'vmalert-logs': 'delete' });
|
|
46
|
+
expect(await onDisk()).toBe(VMALERT_TEXT);
|
|
47
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Release.Binary's plan-time answer: refuse what the plan can already see is wrong, `replace` when
|
|
3
|
+
* the binary's identity moves, and otherwise compare the live file with the declaration.
|
|
4
|
+
*
|
|
5
|
+
* ⛔ THE PINS MUST BE PLAIN VALUES, AND ARE CHECKED EVEN WHILE `directory` IS AN OUTPUT. A pin that
|
|
6
|
+
* is an Output would be computed during the deploy — a fetch by another name — so a malformed or
|
|
7
|
+
* non-literal pin fails the plan here, before a byte is fetched, whatever else is unresolved.
|
|
8
|
+
* ⚠️ A CREATE IS NEVER DIFFED: the engine plans a first deploy without calling diff, and skips
|
|
9
|
+
* the adoption probe while any prop is an Output. A pin wired from another resource's Output on
|
|
10
|
+
* a FIRST deploy therefore reaches no plan-time check; reconcile refuses it before any host call
|
|
11
|
+
* or request, from the props as the stack program declared them (declared-pins.ts). 🔴 Until
|
|
12
|
+
* 2026-09-22 it was checked there for shape only, and a swapped archive with swapped digests
|
|
13
|
+
* installed (apply-pins.test.ts).
|
|
14
|
+
* ⛔ A NEW PIN IS A NEW PATH (binary-form.ts inPlaceRefusal). When the path is resolved and
|
|
15
|
+
* unchanged, a changed pin is refused here; when it is resolved and new, it is a `replace`.
|
|
16
|
+
* ⚠️ WHILE THE DIRECTORY IS STILL AN OUTPUT the path is unknown, and the answer depends on whether
|
|
17
|
+
* the BYTES move, because the path may turn out not to have:
|
|
18
|
+
* - other bytes (or another name) → `replace`. If the path did not move after all, the new
|
|
19
|
+
* generation's create finds the old file, which does not hold its bytes, and refuses
|
|
20
|
+
* (file-converge.ts never overwrites what a generation does not own).
|
|
21
|
+
* - the same bytes from another archive (a re-pin, a repack) → `update`, NEVER `replace`. 🔴 A
|
|
22
|
+
* replace onto the same path would accept the old file as its own (same bytes, same mode) and
|
|
23
|
+
* then Phase 2 would delete the OLD generation — at that same path, taking the new one's file
|
|
24
|
+
* with it. An update reaches reconcile with `olds`, whose in-place guard refuses the same path,
|
|
25
|
+
* and whose move (file-converge.ts) writes the new path before removing the old.
|
|
26
|
+
* ★ Not the engine's default either way: a changed prop is an update by default, which is
|
|
27
|
+
* exactly the in-place overwrite this resource refuses.
|
|
28
|
+
* ★ Create-before-delete: two versions can sit in two directories at once, so nothing forces
|
|
29
|
+
* `deleteFirst`; the old file goes only once the new one is written and verified.
|
|
30
|
+
* ⚠️ HOUSE, NOT UPSTREAM: this reads the live file at plan time and can answer `noop`. Upstream's
|
|
31
|
+
* guidance is a diff that rarely does either (docs/release-binary-upstream.md).
|
|
32
|
+
*/
|
|
33
|
+
import { type Diff, isResolved } from 'alchemy/Diff';
|
|
34
|
+
import type { Input } from 'alchemy/Input';
|
|
35
|
+
import { diffTarget } from '../launchd/file-converge.ts';
|
|
36
|
+
import { resolvedString } from '../launchd/host-effect.ts';
|
|
37
|
+
import type { HostRunner } from '../launchd/runner.ts';
|
|
38
|
+
import { adoptionProblem } from './binary-claim.ts';
|
|
39
|
+
import {
|
|
40
|
+
type ReleaseBinaryAttributes,
|
|
41
|
+
type ReleaseBinaryProps,
|
|
42
|
+
inPlaceRefusal,
|
|
43
|
+
pinProblems,
|
|
44
|
+
pinsMoved,
|
|
45
|
+
} from './binary-form.ts';
|
|
46
|
+
import { NOTHING, desiredBinary, refuse } from './binary-lifecycle.ts';
|
|
47
|
+
|
|
48
|
+
export const diffBinary = async (
|
|
49
|
+
runner: HostRunner,
|
|
50
|
+
news: Input<ReleaseBinaryProps>,
|
|
51
|
+
olds: ReleaseBinaryProps,
|
|
52
|
+
output: ReleaseBinaryAttributes,
|
|
53
|
+
): Promise<Diff | undefined> => {
|
|
54
|
+
const problems = pinProblems((news ?? {}) as Parameters<typeof pinProblems>[0]);
|
|
55
|
+
if (problems.length > 0) throw refuse(output.path, `${problems.join('; ')}. ${NOTHING}`);
|
|
56
|
+
// ⛔ A TAKEOVER IS ONLY EVER OF THE PINNED BINARY (binary-claim.ts): `output` here is a read of a
|
|
57
|
+
// path with no state, so the plan refuses what it would otherwise print as `adopted`.
|
|
58
|
+
const takeover = adoptionProblem(output.sha256, olds.sha256);
|
|
59
|
+
if (takeover !== undefined) throw refuse(output.path, `${takeover}. ${NOTHING}`);
|
|
60
|
+
// ★ pinProblems passed, so every pin — and `name` — is a plain value; only these are read below.
|
|
61
|
+
const pins = news as Pick<ReleaseBinaryProps, 'archive' | 'member' | 'sha256' | 'name'>;
|
|
62
|
+
const directory = resolvedString(news, 'directory');
|
|
63
|
+
const path = directory === undefined ? undefined : `${directory}/${pins.name}`;
|
|
64
|
+
const pinned = pinsMoved(olds, pins);
|
|
65
|
+
if (pinned && path === output.path) {
|
|
66
|
+
throw refuse(output.path, `${inPlaceRefusal(olds, pins)}. ${NOTHING}`);
|
|
67
|
+
}
|
|
68
|
+
// Resolved: a new path is a replace, other bytes or a mode or owner drift an update (diffTarget).
|
|
69
|
+
if (isResolved(news)) return diffTarget(runner, (await desiredBinary(runner, news)).want, output);
|
|
70
|
+
if (path !== undefined) return path === output.path ? undefined : { action: 'replace' };
|
|
71
|
+
if (pins.name !== olds.name || pins.sha256 !== olds.sha256) return { action: 'replace' };
|
|
72
|
+
return pinned ? { action: 'update' } : undefined;
|
|
73
|
+
};
|