@homeflare/alchemy 0.8.0 → 0.10.1

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.
Files changed (247) hide show
  1. package/README.md +22 -11
  2. package/dist/caddy/config-lifecycle.d.ts +1 -1
  3. package/dist/caddy/config.d.ts.map +1 -1
  4. package/dist/caddy/index.js +221 -53
  5. package/dist/caddy/index.js.map +13 -9
  6. package/dist/launchd/fake-runner.d.ts +1 -0
  7. package/dist/launchd/fake-runner.d.ts.map +1 -1
  8. package/dist/launchd/fake-sudo.d.ts +1 -0
  9. package/dist/launchd/fake-sudo.d.ts.map +1 -1
  10. package/dist/launchd/host-effect.d.ts +9 -18
  11. package/dist/launchd/host-effect.d.ts.map +1 -1
  12. package/dist/launchd/host-file-lifecycle.d.ts +14 -1
  13. package/dist/launchd/host-file-lifecycle.d.ts.map +1 -1
  14. package/dist/launchd/host-file.d.ts +2 -1
  15. package/dist/launchd/host-file.d.ts.map +1 -1
  16. package/dist/launchd/index.js +345 -86
  17. package/dist/launchd/index.js.map +18 -12
  18. package/dist/launchd/job-lifecycle.d.ts +8 -1
  19. package/dist/launchd/job-lifecycle.d.ts.map +1 -1
  20. package/dist/launchd/job-preflight.d.ts +13 -1
  21. package/dist/launchd/job-preflight.d.ts.map +1 -1
  22. package/dist/launchd/job.d.ts +2 -1
  23. package/dist/launchd/job.d.ts.map +1 -1
  24. package/dist/launchd/runner.d.ts +7 -0
  25. package/dist/launchd/runner.d.ts.map +1 -1
  26. package/dist/launchd/sudo-acl.d.ts +25 -0
  27. package/dist/launchd/sudo-acl.d.ts.map +1 -0
  28. package/dist/launchd/sudo-guard.d.ts +31 -4
  29. package/dist/launchd/sudo-guard.d.ts.map +1 -1
  30. package/dist/launchd/sudo-runner.d.ts +3 -3
  31. package/dist/launchd/sudo-runner.d.ts.map +1 -1
  32. package/dist/launchd/sudo-said.d.ts +10 -0
  33. package/dist/launchd/sudo-said.d.ts.map +1 -0
  34. package/dist/openbao/auth-method-reconcile.d.ts +6 -2
  35. package/dist/openbao/auth-method-reconcile.d.ts.map +1 -1
  36. package/dist/openbao/auth-method.d.ts.map +1 -1
  37. package/dist/openbao/auth-role.d.ts.map +1 -1
  38. package/dist/openbao/cloudflare-role.d.ts.map +1 -1
  39. package/dist/openbao/fake-bao.d.ts +18 -0
  40. package/dist/openbao/fake-bao.d.ts.map +1 -1
  41. package/dist/openbao/fake-core.d.ts +39 -0
  42. package/dist/openbao/fake-core.d.ts.map +1 -0
  43. package/dist/openbao/fake-families.d.ts +6 -3
  44. package/dist/openbao/fake-families.d.ts.map +1 -1
  45. package/dist/openbao/fake-mounts.d.ts +16 -0
  46. package/dist/openbao/fake-mounts.d.ts.map +1 -0
  47. package/dist/openbao/fake-stack.d.ts +5 -1
  48. package/dist/openbao/fake-stack.d.ts.map +1 -1
  49. package/dist/openbao/index.js +541 -270
  50. package/dist/openbao/index.js.map +26 -21
  51. package/dist/openbao/jwt-config.d.ts.map +1 -1
  52. package/dist/openbao/jwt-role.d.ts.map +1 -1
  53. package/dist/openbao/kubernetes-role.d.ts.map +1 -1
  54. package/dist/openbao/mfa-enforcement.d.ts +6 -2
  55. package/dist/openbao/mfa-enforcement.d.ts.map +1 -1
  56. package/dist/openbao/mfa-totp.d.ts +6 -2
  57. package/dist/openbao/mfa-totp.d.ts.map +1 -1
  58. package/dist/openbao/mount-reconcile.d.ts +5 -1
  59. package/dist/openbao/mount-reconcile.d.ts.map +1 -1
  60. package/dist/openbao/mount.d.ts.map +1 -1
  61. package/dist/openbao/pki-role.d.ts.map +1 -1
  62. package/dist/openbao/plugin-reconcile.d.ts +6 -2
  63. package/dist/openbao/plugin-reconcile.d.ts.map +1 -1
  64. package/dist/openbao/plugin.d.ts.map +1 -1
  65. package/dist/openbao/policy.d.ts.map +1 -1
  66. package/dist/openbao/proxmox-role.d.ts.map +1 -1
  67. package/dist/openbao/role-reconcile.d.ts +11 -1
  68. package/dist/openbao/role-reconcile.d.ts.map +1 -1
  69. package/dist/openbao/ssh-role.d.ts.map +1 -1
  70. package/dist/ownership/adopt.d.ts +52 -0
  71. package/dist/ownership/adopt.d.ts.map +1 -0
  72. package/dist/ownership/probe.d.ts +13 -0
  73. package/dist/ownership/probe.d.ts.map +1 -0
  74. package/dist/ownership/resume.d.ts +40 -0
  75. package/dist/ownership/resume.d.ts.map +1 -0
  76. package/dist/ownership/rows.d.ts +33 -0
  77. package/dist/ownership/rows.d.ts.map +1 -0
  78. package/dist/ownership/whole.d.ts +14 -0
  79. package/dist/ownership/whole.d.ts.map +1 -0
  80. package/dist/proxmox/ceph-pool-form.d.ts +3 -3
  81. package/dist/proxmox/ceph-pool.d.ts.map +1 -1
  82. package/dist/proxmox/fake-bao-env.d.ts +3 -0
  83. package/dist/proxmox/fake-bao-env.d.ts.map +1 -0
  84. package/dist/proxmox/fake-pve-lxc.d.ts +42 -0
  85. package/dist/proxmox/fake-pve-lxc.d.ts.map +1 -0
  86. package/dist/proxmox/fake-pve.d.ts +38 -0
  87. package/dist/proxmox/fake-pve.d.ts.map +1 -0
  88. package/dist/proxmox/index.d.ts +6 -2
  89. package/dist/proxmox/index.d.ts.map +1 -1
  90. package/dist/proxmox/index.js +970 -186
  91. package/dist/proxmox/index.js.map +22 -9
  92. package/dist/proxmox/lxc-create-form.d.ts +6 -0
  93. package/dist/proxmox/lxc-create-form.d.ts.map +1 -0
  94. package/dist/proxmox/lxc-harness.d.ts +34 -0
  95. package/dist/proxmox/lxc-harness.d.ts.map +1 -0
  96. package/dist/proxmox/lxc-identity.d.ts +18 -0
  97. package/dist/proxmox/lxc-identity.d.ts.map +1 -0
  98. package/dist/proxmox/lxc-judge.d.ts +46 -0
  99. package/dist/proxmox/lxc-judge.d.ts.map +1 -0
  100. package/dist/proxmox/lxc-lifecycle.d.ts +68 -0
  101. package/dist/proxmox/lxc-lifecycle.d.ts.map +1 -0
  102. package/dist/proxmox/lxc-props.d.ts +139 -0
  103. package/dist/proxmox/lxc-props.d.ts.map +1 -0
  104. package/dist/proxmox/lxc-volume.d.ts +29 -0
  105. package/dist/proxmox/lxc-volume.d.ts.map +1 -0
  106. package/dist/proxmox/lxc-wire.d.ts +51 -0
  107. package/dist/proxmox/lxc-wire.d.ts.map +1 -0
  108. package/dist/proxmox/lxc.d.ts +27 -47
  109. package/dist/proxmox/lxc.d.ts.map +1 -1
  110. package/dist/proxmox/network-apply-read.d.ts +1 -1
  111. package/dist/proxmox/network-apply-read.d.ts.map +1 -1
  112. package/dist/proxmox/pbs-datastore.d.ts.map +1 -1
  113. package/dist/proxmox/resource.d.ts.map +1 -1
  114. package/dist/proxmox/update-guard.d.ts +27 -0
  115. package/dist/proxmox/update-guard.d.ts.map +1 -0
  116. package/dist/verify/args.d.ts +16 -0
  117. package/dist/verify/args.d.ts.map +1 -0
  118. package/dist/verify/cli.d.ts +3 -0
  119. package/dist/verify/cli.d.ts.map +1 -0
  120. package/dist/verify/cli.js +370 -0
  121. package/dist/verify/cli.js.map +17 -0
  122. package/dist/verify/fake-engine.d.ts +65 -0
  123. package/dist/verify/fake-engine.d.ts.map +1 -0
  124. package/dist/verify/index.d.ts +16 -0
  125. package/dist/verify/index.d.ts.map +1 -0
  126. package/dist/verify/index.js +347 -0
  127. package/dist/verify/index.js.map +16 -0
  128. package/dist/verify/plan-scope.d.ts +14 -0
  129. package/dist/verify/plan-scope.d.ts.map +1 -0
  130. package/dist/verify/recheck.d.ts +42 -0
  131. package/dist/verify/recheck.d.ts.map +1 -0
  132. package/dist/verify/report.d.ts +6 -0
  133. package/dist/verify/report.d.ts.map +1 -0
  134. package/dist/verify/rows.d.ts +67 -0
  135. package/dist/verify/rows.d.ts.map +1 -0
  136. package/dist/verify/spy.d.ts +43 -0
  137. package/dist/verify/spy.d.ts.map +1 -0
  138. package/dist/verify/verify.d.ts +43 -0
  139. package/dist/verify/verify.d.ts.map +1 -0
  140. package/docs/adopt-verify.md +119 -0
  141. package/docs/adopted-deploys.md +85 -0
  142. package/docs/credentials.md +15 -0
  143. package/docs/launchd-sudo.md +31 -6
  144. package/docs/launchd.md +7 -3
  145. package/docs/ownership.md +113 -0
  146. package/docs/proxmox-lxc.md +196 -0
  147. package/docs/proxmox.md +12 -0
  148. package/package.json +9 -2
  149. package/src/caddy/adopt-scope.test.ts +1 -1
  150. package/src/caddy/config-lifecycle.ts +1 -1
  151. package/src/caddy/config.ts +2 -1
  152. package/src/launchd/adopt-apply.test.ts +166 -0
  153. package/src/launchd/fake-runner.ts +26 -4
  154. package/src/launchd/host-effect.ts +1 -33
  155. package/src/launchd/host-file-lifecycle.ts +39 -14
  156. package/src/launchd/host-file.ts +13 -4
  157. package/src/launchd/job-lifecycle.ts +22 -14
  158. package/src/launchd/job-preflight.ts +18 -1
  159. package/src/launchd/job.ts +13 -4
  160. package/src/launchd/runner.ts +7 -0
  161. package/src/launchd/sudo-acl.ts +68 -0
  162. package/src/launchd/sudo-chain.test.ts +121 -0
  163. package/src/launchd/sudo-guard.ts +89 -10
  164. package/src/launchd/sudo-modes.test.ts +135 -0
  165. package/src/launchd/sudo-runner.ts +40 -59
  166. package/src/launchd/sudo-said.ts +58 -0
  167. package/src/openbao/README.md +5 -2
  168. package/src/openbao/REPLACE.md +13 -11
  169. package/src/openbao/adopt-core.test.ts +119 -0
  170. package/src/openbao/adopt-families.test.ts +97 -0
  171. package/src/openbao/adopt-holes.test.ts +168 -0
  172. package/src/openbao/adopt-recovery.test.ts +71 -0
  173. package/src/openbao/auth-method-reconcile.ts +15 -3
  174. package/src/openbao/auth-method.ts +15 -6
  175. package/src/openbao/auth-role.ts +14 -4
  176. package/src/openbao/cloudflare-role.ts +17 -4
  177. package/src/openbao/fake-bao.ts +52 -0
  178. package/src/openbao/fake-core.ts +141 -0
  179. package/src/openbao/fake-families.ts +11 -5
  180. package/src/openbao/fake-mounts.ts +74 -0
  181. package/src/openbao/fake-stack.ts +17 -4
  182. package/src/openbao/jwt-config.ts +10 -7
  183. package/src/openbao/jwt-role.ts +10 -7
  184. package/src/openbao/kubernetes-role.ts +13 -7
  185. package/src/openbao/mfa-enforcement.ts +20 -6
  186. package/src/openbao/mfa-totp.ts +22 -7
  187. package/src/openbao/mount-move.test.ts +2 -35
  188. package/src/openbao/mount-reconcile.ts +13 -2
  189. package/src/openbao/mount.ts +15 -6
  190. package/src/openbao/pki-role.ts +15 -4
  191. package/src/openbao/plugin-reconcile.ts +16 -5
  192. package/src/openbao/plugin.ts +17 -6
  193. package/src/openbao/policy.ts +17 -4
  194. package/src/openbao/proxmox-role.ts +13 -4
  195. package/src/openbao/rename-adoption.test.ts +32 -19
  196. package/src/openbao/role-reconcile.ts +23 -0
  197. package/src/openbao/ssh-role.ts +14 -4
  198. package/src/ownership/adopt.ts +122 -0
  199. package/src/ownership/ownership.test.ts +200 -0
  200. package/src/ownership/probe.ts +65 -0
  201. package/src/ownership/resume.ts +118 -0
  202. package/src/ownership/rows.ts +117 -0
  203. package/src/ownership/whole.test.ts +39 -0
  204. package/src/ownership/whole.ts +60 -0
  205. package/src/proxmox/adopt-noop.test.ts +112 -0
  206. package/src/proxmox/ceph-pool-adopt.test.ts +120 -0
  207. package/src/proxmox/ceph-pool-form.ts +3 -3
  208. package/src/proxmox/ceph-pool.ts +10 -3
  209. package/src/proxmox/fake-bao-env.ts +28 -0
  210. package/src/proxmox/fake-pve-lxc.ts +210 -0
  211. package/src/proxmox/fake-pve.ts +75 -0
  212. package/src/proxmox/index.test.ts +6 -6
  213. package/src/proxmox/index.ts +6 -2
  214. package/src/proxmox/lxc-adopt.test.ts +170 -0
  215. package/src/proxmox/lxc-create-form.ts +76 -0
  216. package/src/proxmox/lxc-create.test.ts +126 -0
  217. package/src/proxmox/lxc-guards.test.ts +158 -0
  218. package/src/proxmox/lxc-harness.ts +150 -0
  219. package/src/proxmox/lxc-identity.ts +43 -0
  220. package/src/proxmox/lxc-judge.test.ts +175 -0
  221. package/src/proxmox/lxc-judge.ts +196 -0
  222. package/src/proxmox/lxc-lifecycle.ts +200 -0
  223. package/src/proxmox/lxc-ownership.test.ts +159 -0
  224. package/src/proxmox/lxc-props.ts +215 -0
  225. package/src/proxmox/lxc-read.test.ts +60 -0
  226. package/src/proxmox/lxc-volume.test.ts +96 -0
  227. package/src/proxmox/lxc-volume.ts +153 -0
  228. package/src/proxmox/lxc-wire.ts +210 -0
  229. package/src/proxmox/lxc.ts +216 -93
  230. package/src/proxmox/network-apply-read.ts +3 -1
  231. package/src/proxmox/pbs-datastore.ts +4 -3
  232. package/src/proxmox/resource.ts +7 -7
  233. package/src/proxmox/update-guard.ts +31 -0
  234. package/src/verify/args.ts +82 -0
  235. package/src/verify/cli.test.ts +86 -0
  236. package/src/verify/cli.ts +49 -0
  237. package/src/verify/fake-engine.ts +182 -0
  238. package/src/verify/index.ts +37 -0
  239. package/src/verify/plan-scope.ts +34 -0
  240. package/src/verify/recheck.test.ts +56 -0
  241. package/src/verify/recheck.ts +71 -0
  242. package/src/verify/report.ts +52 -0
  243. package/src/verify/rows.ts +210 -0
  244. package/src/verify/spy.test.ts +141 -0
  245. package/src/verify/spy.ts +160 -0
  246. package/src/verify/verify.test.ts +146 -0
  247. package/src/verify/verify.ts +185 -0
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Whether an update has anything to write — decided ONCE for every PVE and PBS family.
3
+ *
4
+ * ⛔ AN ADOPTED ROW IS RECONCILED EVEN WHEN ITS DIFF SAID `noop`, SO THIS GUARD IS WHAT MAKES
5
+ * ADOPTION FREE. alchemy beta.79 Plan.ts sets `forceUpdateAfterAdoption` after the cold-start
6
+ * probe and turns a `noop` diff into an update; Apply.ts then calls `reconcile` for the
7
+ * `adopted` action exactly as for `update`. The plan prints `adopted` either way, so nothing on
8
+ * screen tells a matching object from a drifting one. docs/adopt-verify.md has the table of
9
+ * what each family does on that path.
10
+ *
11
+ * 🔴 THE FAMILY THAT DID NOT HAVE IT. `Proxmox.CephPool` wrote its own reconcile and PUT the
12
+ * declared set whenever the pool existed, so adopting a pool that already matched sent
13
+ * `setpool` and forked a worker on the live cluster (found 2026-09-21 by tracing every family).
14
+ * resource.ts and pbs-datastore.ts each had the guard inline; three copies of one predicate is
15
+ * how the fourth family forgets it, so it lives here and all three call it.
16
+ *
17
+ * ★ `matches` IS THE SAME PREDICATE `diff` USES, so "the diff said noop" and "reconcile writes
18
+ * nothing" cannot disagree. A field left OUT of `matches` is one the family does not manage, so
19
+ * its drift is not this write's to repair.
20
+ *
21
+ * ⚠️ AN EMPTY FORM IS ALSO NOT A WRITE. `updateForm` can legitimately answer `{}` — a storage
22
+ * declaring only `storage`, `type` and its locator has no mutable field at all — and PUTting an
23
+ * empty body is a pointless write at best and a 400 that reads as a broken provider at worst.
24
+ * (Moved here from resource.ts with the guard it explains.)
25
+ */
26
+ export const formToSend = <Attributes, Props, Form extends object>(
27
+ matches: (attributes: Attributes, props: Props) => boolean,
28
+ live: Attributes,
29
+ props: Props,
30
+ form: Form,
31
+ ): Form | undefined => (matches(live, props) || Object.keys(form).length === 0 ? undefined : form);
@@ -0,0 +1,82 @@
1
+ /**
2
+ * `hf-adopt-verify`'s flags — the ones `alchemy plan` takes, so a stack script can swap one
3
+ * command for the other.
4
+ *
5
+ * ★ `node:util` parseArgs, NOT effect's CLI module. Alchemy builds its CLI on
6
+ * `effect/unstable/cli`, but that needs a CliConfig and a Terminal layer to parse six flags; the
7
+ * standard library parses them with no service at all, which keeps this pure and testable.
8
+ * ⛔ `--stage` HAS NO GUESSED DEFAULT. Alchemy falls back to `live_$USER`; a gate that silently
9
+ * verified the wrong stage would pass for the wrong reason. It comes from the flag or from
10
+ * `$ALCHEMY_STAGE`, or the run stops.
11
+ */
12
+ import { parseArgs } from 'node:util';
13
+ import type { VerifyOptions, VerifyTarget } from './verify.ts';
14
+
15
+ export const USAGE = `Usage: hf-adopt-verify --stage <stage> [--config alchemy.run.ts] [options]
16
+
17
+ Plans the stack with Alchemy's own planner, never writes, and reports each row
18
+ without a state row: what the engine planned, the provider's read and its own
19
+ diff (before Alchemy forces adopted rows to update), and the declared fields
20
+ that differ from the live object. Exits 0 when every row is a no-op, 1 when
21
+ any is not, 2 when it could not tell.
22
+
23
+ -c, --config <file> stack entrypoint (default alchemy.run.ts)
24
+ --stage <stage> stage to verify (default $ALCHEMY_STAGE; required)
25
+ --profile <name> Alchemy auth profile
26
+ --env-file <file> .env file layered under the environment
27
+ --all report every declared row and pending deletion
28
+ --json print the report as JSON
29
+ -h, --help this text
30
+ `;
31
+
32
+ export type Parsed =
33
+ | { readonly kind: 'help' }
34
+ | { readonly kind: 'error'; readonly message: string }
35
+ | {
36
+ readonly kind: 'run';
37
+ readonly target: VerifyTarget;
38
+ readonly options: VerifyOptions;
39
+ readonly json: boolean;
40
+ };
41
+
42
+ const parse = (argv: readonly string[]) =>
43
+ parseArgs({
44
+ args: [...argv],
45
+ allowPositionals: false,
46
+ options: {
47
+ all: { type: 'boolean', default: false },
48
+ config: { type: 'string', short: 'c', default: 'alchemy.run.ts' },
49
+ 'env-file': { type: 'string' },
50
+ help: { type: 'boolean', short: 'h', default: false },
51
+ json: { type: 'boolean', default: false },
52
+ profile: { type: 'string' },
53
+ stage: { type: 'string' },
54
+ },
55
+ strict: true,
56
+ });
57
+
58
+ /** Parse argv (without the runtime and script) against the environment. Never throws. */
59
+ export const parseVerifyArgs = (
60
+ argv: readonly string[],
61
+ env: Readonly<Record<string, string | undefined>>,
62
+ ): Parsed => {
63
+ let parsed: ReturnType<typeof parse>;
64
+ try {
65
+ parsed = parse(argv);
66
+ } catch (error) {
67
+ return { kind: 'error', message: error instanceof Error ? error.message : String(error) };
68
+ }
69
+ const { values } = parsed;
70
+ if (values.help) return { kind: 'help' };
71
+ const stage = values.stage ?? env['ALCHEMY_STAGE'];
72
+ if (stage === undefined || stage === '') {
73
+ return { kind: 'error', message: 'pass --stage (or set ALCHEMY_STAGE): no stage is guessed' };
74
+ }
75
+ const target: VerifyTarget = {
76
+ entrypoint: values.config,
77
+ stage,
78
+ ...(values.profile === undefined ? {} : { profile: values.profile }),
79
+ ...(values['env-file'] === undefined ? {} : { envFile: values['env-file'] }),
80
+ };
81
+ return { json: values.json, kind: 'run', options: { all: values.all }, target };
82
+ };
@@ -0,0 +1,86 @@
1
+ /**
2
+ * The bin's two pure halves: its flags (args.ts) and its text (report.ts).
3
+ *
4
+ * ⛔ NO STAGE IS GUESSED. Alchemy defaults `--stage` to `live_$USER`; a gate that verified that by
5
+ * accident would pass while the real stage went unchecked, so a missing stage is an error here.
6
+ */
7
+ import { describe, expect, test } from 'bun:test';
8
+ import { parseVerifyArgs } from './args.ts';
9
+ import { exitCodeOf, formatReport } from './report.ts';
10
+ import type { AdoptRow } from './rows.ts';
11
+ import type { AdoptReport } from './verify.ts';
12
+
13
+ describe('parseVerifyArgs', () => {
14
+ test('takes the flags alchemy plan takes', () => {
15
+ const parsed = parseVerifyArgs(
16
+ ['-c', 'alchemy.pbs.ts', '--stage', 'live', '--profile', 'p', '--env-file', '.env', '--all'],
17
+ {},
18
+ );
19
+ expect(parsed).toEqual({
20
+ json: false,
21
+ kind: 'run',
22
+ options: { all: true },
23
+ target: { entrypoint: 'alchemy.pbs.ts', envFile: '.env', profile: 'p', stage: 'live' },
24
+ });
25
+ });
26
+
27
+ test('defaults the entrypoint and reads ALCHEMY_STAGE, but never guesses a stage', () => {
28
+ const parsed = parseVerifyArgs(['--json'], { ALCHEMY_STAGE: 'live' });
29
+ expect(parsed).toMatchObject({ json: true, target: { entrypoint: 'alchemy.run.ts' } });
30
+ expect(parseVerifyArgs([], { USER: 'tim' })).toMatchObject({ kind: 'error' });
31
+ });
32
+
33
+ test('an unknown flag or a positional is an error, and --help is help', () => {
34
+ expect(parseVerifyArgs(['--stage', 'live', '--yes'], {})).toMatchObject({ kind: 'error' });
35
+ expect(parseVerifyArgs(['--stage', 'live', 'alchemy.run.ts'], {})).toMatchObject({
36
+ kind: 'error',
37
+ });
38
+ expect(parseVerifyArgs(['-h'], {})).toEqual({ kind: 'help' });
39
+ });
40
+ });
41
+
42
+ const row = (over: Partial<AdoptRow>): AdoptRow => ({
43
+ bindings: 0,
44
+ changed: [],
45
+ diff: 'noop',
46
+ fqn: 'house',
47
+ ok: true,
48
+ planned: 'adopted',
49
+ read: 'found',
50
+ stateRow: false,
51
+ type: 'Proxmox.Pool',
52
+ why: '',
53
+ ...over,
54
+ });
55
+
56
+ const report = (rows: AdoptRow[]): AdoptReport => ({
57
+ declared: 5,
58
+ rows,
59
+ stack: 'HomeFlareProxmox',
60
+ stage: 'live',
61
+ });
62
+
63
+ describe('formatReport', () => {
64
+ test('a clean report exits 0 and says so', () => {
65
+ const clean = report([row({})]);
66
+ expect(exitCodeOf(clean)).toBe(0);
67
+ expect(formatReport(clean, false)).toContain('every row is a no-op');
68
+ });
69
+
70
+ test('a failing row exits 1, shows its reason and field names, never values', () => {
71
+ const dirty = report([
72
+ row({ changed: ['comment'], diff: 'update', ok: false, why: 'the deploy writes' }),
73
+ ]);
74
+ const text = formatReport(dirty, false);
75
+ expect(exitCodeOf(dirty)).toBe(1);
76
+ expect(text).toContain('FAIL');
77
+ expect(text).toContain('changed: comment');
78
+ expect(text).toContain('the deploy writes');
79
+ expect(text).toContain('1 row(s) are NOT a no-op');
80
+ });
81
+
82
+ test('nothing to verify is a pass that says why', () => {
83
+ expect(formatReport(report([]), false)).toContain('every declared row already has state');
84
+ expect(exitCodeOf(report([]))).toBe(0);
85
+ });
86
+ });
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * `hf-adopt-verify` — the bin. Parse, verify, print, exit 0 / 1 / 2.
4
+ *
5
+ * ★ `runMain` IS ALCHEMY'S (alchemy/Util/PlatformServices), so this runs under bun or node the way
6
+ * `alchemy` itself does, and exits once the report is out rather than lingering on keep-alive
7
+ * sockets. Run it where the stack's `alchemy` runs: `bunx --bun hf-adopt-verify …` next to
8
+ * `bun ./node_modules/alchemy/bin/cli.js plan …`, because the entrypoint it imports is
9
+ * TypeScript.
10
+ * ⛔ EXIT 2 IS "COULD NOT TELL", NEVER A PASS. A plan that fails — a provider that dies, an
11
+ * `adopt(false)` row that is not ours, a state store it cannot read — prints the cause and exits
12
+ * 2, so a gate reading `!= 0` stops either way.
13
+ */
14
+ import { runMain } from 'alchemy/Util/PlatformServices';
15
+ import * as Cause from 'effect/Cause';
16
+ import * as Console from 'effect/Console';
17
+ import * as Effect from 'effect/Effect';
18
+ import { USAGE, parseVerifyArgs } from './args.ts';
19
+ import { exitCodeOf, formatReport } from './report.ts';
20
+ import { verifyStack } from './verify.ts';
21
+
22
+ const setExit = (code: number) =>
23
+ Effect.sync(() => {
24
+ process.exitCode = code;
25
+ });
26
+
27
+ const program = Effect.gen(function* () {
28
+ const parsed = parseVerifyArgs(process.argv.slice(2), process.env);
29
+ if (parsed.kind === 'help') return yield* Console.log(USAGE);
30
+ if (parsed.kind === 'error') {
31
+ yield* Console.error(`hf-adopt-verify: ${parsed.message}\n\n${USAGE}`);
32
+ return yield* setExit(2);
33
+ }
34
+ const report = yield* verifyStack(parsed.target, parsed.options);
35
+ yield* Console.log(
36
+ parsed.json
37
+ ? JSON.stringify(report, null, 2)
38
+ : formatReport(report, parsed.options.all === true),
39
+ );
40
+ yield* setExit(exitCodeOf(report));
41
+ }).pipe(
42
+ Effect.catchCause((cause) =>
43
+ Console.error(`hf-adopt-verify: the plan could not be verified\n${Cause.pretty(cause)}`).pipe(
44
+ Effect.andThen(setExit(2)),
45
+ ),
46
+ ),
47
+ );
48
+
49
+ runMain(program);
@@ -0,0 +1,182 @@
1
+ /**
2
+ * A test-only stack: Alchemy's real Plan and Apply over an in-memory state store, and a fake family
3
+ * whose "cloud" is a Map — so the verifier runs against the engine's own plans with no network.
4
+ *
5
+ * ★ THE ENGINE, NOT A HAND-BUILT PLAN. What the verifier claims is about alchemy beta.79: that an
6
+ * adopted row's `diff` answer is lost to `forceUpdateAfterAdoption`, that Apply then reconciles
7
+ * it, and that a watched plan never writes. openbao/fake-stack.ts measured the same engine for
8
+ * the Bao families; this one is family-neutral and records every provider call in order.
9
+ * ⛔ TEST-ONLY. No provider imports this file.
10
+ */
11
+ import * as Alchemy from 'alchemy';
12
+ import { AdoptPolicy, Unowned } from 'alchemy/AdoptPolicy';
13
+ import { provideFreshArtifactStore } from 'alchemy/Artifacts';
14
+ import { isResolved } from 'alchemy/Diff';
15
+ import * as Provider from 'alchemy/Provider';
16
+ import * as Effect from 'effect/Effect';
17
+ import * as Layer from 'effect/Layer';
18
+ import { type AdoptReport, type VerifyOptions, verifySession } from './verify.ts';
19
+
20
+ export interface ThingProps {
21
+ name: string;
22
+ comment?: string;
23
+ }
24
+ export interface ThingAttributes {
25
+ name: string;
26
+ comment: string;
27
+ }
28
+
29
+ export interface Thing extends Alchemy.Resource<'Test.Thing', ThingProps, ThingAttributes> {}
30
+ export const Thing = Alchemy.Resource<Thing>('Test.Thing');
31
+
32
+ /** The same object with no `diff`, like a provider that never wrote one. */
33
+ export interface Blind extends Alchemy.Resource<'Test.Blind', ThingProps, ThingAttributes> {}
34
+ export const Blind = Alchemy.Resource<Blind>('Test.Blind');
35
+
36
+ /**
37
+ * The same object with a `diff` that compares the RECORDED props with the declaration and never
38
+ * the live object — the shape of Alchemy's own `Cloudflare.R2Bucket` diff (beta.79
39
+ * Cloudflare/R2/Bucket.ts: `olds.domains` against `news.domains`). recheck.ts exists for it.
40
+ */
41
+ export interface Recorded extends Alchemy.Resource<'Test.Recorded', ThingProps, ThingAttributes> {}
42
+ export const Recorded = Alchemy.Resource<Recorded>('Test.Recorded');
43
+
44
+ /** The fake cloud: what exists, what is someone else's, and every call made to it, in order. */
45
+ export interface Cloud {
46
+ readonly live: Map<string, string>;
47
+ readonly unowned: Set<string>;
48
+ readonly calls: string[];
49
+ }
50
+
51
+ export const cloudOf = (live: Record<string, string> = {}): Cloud => ({
52
+ calls: [],
53
+ live: new Map(Object.entries(live)),
54
+ unowned: new Set(),
55
+ });
56
+
57
+ /** Every call that would change the cloud. */
58
+ export const writesOf = (cloud: Cloud): string[] =>
59
+ cloud.calls.filter((call) => call.startsWith('reconcile') || call.startsWith('delete'));
60
+
61
+ const lifecycle = (cloud: Cloud) => ({
62
+ list: () => Effect.succeed([]),
63
+ read: ({ olds }: { olds: ThingProps }) =>
64
+ Effect.sync(() => {
65
+ cloud.calls.push(`read ${olds.name}`);
66
+ const comment = cloud.live.get(olds.name);
67
+ if (comment === undefined) return undefined;
68
+ const found = { comment, name: olds.name };
69
+ return cloud.unowned.has(olds.name) ? Unowned(found) : found;
70
+ }),
71
+ reconcile: ({ news }: { news: ThingProps }) =>
72
+ Effect.sync(() => {
73
+ cloud.calls.push(`reconcile ${news.name}`);
74
+ cloud.live.set(news.name, news.comment ?? '');
75
+ return { comment: news.comment ?? '', name: news.name };
76
+ }),
77
+ delete: ({ olds }: { olds: ThingProps }) =>
78
+ Effect.sync(() => {
79
+ cloud.calls.push(`delete ${olds.name}`);
80
+ cloud.live.delete(olds.name);
81
+ }),
82
+ });
83
+
84
+ /** Both fake families over `cloud` — also what tests/fixtures/verify-stack.ts registers. */
85
+ export const thingProviders = (cloud: Cloud) =>
86
+ Layer.mergeAll(
87
+ Provider.effect(
88
+ Thing,
89
+ Effect.succeed(
90
+ Thing.Provider.of({
91
+ ...lifecycle(cloud),
92
+ diff: ({ news, output }) =>
93
+ Effect.sync(() => {
94
+ if (output === undefined || !isResolved(news)) return undefined;
95
+ cloud.calls.push(`diff ${news.name}`);
96
+ return cloud.live.get(news.name) === (news.comment ?? '')
97
+ ? ({ action: 'noop' } as const)
98
+ : ({ action: 'update' } as const);
99
+ }),
100
+ }),
101
+ ),
102
+ ),
103
+ Provider.effect(Blind, Effect.succeed(Blind.Provider.of(lifecycle(cloud)))),
104
+ Provider.effect(
105
+ Recorded,
106
+ Effect.succeed(
107
+ Recorded.Provider.of({
108
+ ...lifecycle(cloud),
109
+ diff: ({ news, olds }) =>
110
+ Effect.sync(() => {
111
+ if (!isResolved(news)) return undefined;
112
+ cloud.calls.push(`diff ${news.name}`);
113
+ return (olds.comment ?? '') === (news.comment ?? '')
114
+ ? ({ action: 'noop' } as const)
115
+ : ({ action: 'update' } as const);
116
+ }),
117
+ }),
118
+ ),
119
+ ),
120
+ );
121
+
122
+ /** A stack body: resource declarations, as an `alchemy.run.ts` would write them. */
123
+ export type Body = Effect.Effect<unknown, unknown, unknown>;
124
+
125
+ type Compiled = { readonly name: string; readonly stage: string; readonly services: never };
126
+ type PlanView = { readonly resources: Readonly<Record<string, { readonly action: string }>> };
127
+
128
+ export interface FakeEngine {
129
+ /** Plan and apply `body`, as `alchemy deploy --adopt` would; resolves to the planned actions. */
130
+ readonly deploy: (body: Body) => Promise<Record<string, string>>;
131
+ /** Verify `body` against what the earlier deploys recorded. */
132
+ readonly verify: (body: Body, options?: VerifyOptions) => Promise<AdoptReport>;
133
+ }
134
+
135
+ /**
136
+ * One stack over one state store and any providers, shared by every call — a family's own test
137
+ * hands in its real provider over a fake transport (proxmox/ceph-pool-adopt.test.ts).
138
+ * ⚠️ THE CASTS ARE AT THE ENGINE'S TYPED BOUNDARY — openbao/fake-stack.ts has the reasoning.
139
+ */
140
+ export const engineOver = <ROut, E, RIn>(layer: Layer.Layer<ROut, E, RIn>): FakeEngine => {
141
+ const state = Alchemy.inMemoryState();
142
+ const stack = Alchemy.Stack as unknown as (
143
+ name: string,
144
+ options: { providers: typeof layer; state: typeof state },
145
+ body: Body,
146
+ ) => Effect.Effect<Compiled, unknown, never>;
147
+ const plan = Alchemy.Plan.make as unknown as (c: Compiled) => Effect.Effect<PlanView, unknown>;
148
+ const apply = Alchemy.apply as unknown as (planned: PlanView) => Effect.Effect<unknown, unknown>;
149
+
150
+ const run = <A>(body: Body, next: (compiled: Compiled) => Effect.Effect<A, unknown, unknown>) =>
151
+ Effect.runPromise(
152
+ Effect.gen(function* () {
153
+ const compiled = yield* stack('VerifyStack', { providers: layer, state }, body);
154
+ return yield* next(compiled).pipe(Effect.provide(Layer.succeedContext(compiled.services)));
155
+ }).pipe(
156
+ Effect.provideService(AdoptPolicy, true),
157
+ Effect.provideService(Alchemy.Stage, 'test'),
158
+ Effect.provide(state),
159
+ Effect.scoped,
160
+ ) as Effect.Effect<A>,
161
+ );
162
+
163
+ return {
164
+ deploy: (body) =>
165
+ run(body, (compiled) =>
166
+ Effect.gen(function* () {
167
+ const planned = yield* plan(compiled);
168
+ yield* apply(planned);
169
+ return Object.fromEntries(
170
+ Object.entries(planned.resources).map(([fqn, node]) => [fqn, node.action]),
171
+ );
172
+ }).pipe(provideFreshArtifactStore),
173
+ ),
174
+ verify: (body, options) =>
175
+ run(body, (compiled) =>
176
+ verifySession({ context: compiled.services, stack: compiled as never }, options),
177
+ ),
178
+ };
179
+ };
180
+
181
+ /** The fake family over `cloud`. */
182
+ export const fakeEngine = (cloud: Cloud): FakeEngine => engineOver(thingProviders(cloud));
@@ -0,0 +1,37 @@
1
+ /**
2
+ * `@homeflare/alchemy/verify` — prove a deploy's adoptions are no-ops before it runs.
3
+ *
4
+ * ★ ONE TOOL FOR EVERY STACK, NOT A TEST PER REPO. A stack runs `hf-adopt-verify --config
5
+ * alchemy.run.ts --stage live` before a gated deploy, or calls `verifyStack` from its own
6
+ * script; both plan with Alchemy's planner and never write. docs/adopt-verify.md has the why,
7
+ * the report's columns, and what each kit family does on an adopted deploy.
8
+ * ⛔ A SUBPATH OF ITS OWN: it imports the stack module from disk and reads the state store, which
9
+ * is host access, so it never rides along with the runtime-neutral root entry.
10
+ */
11
+ export { type Parsed, USAGE, parseVerifyArgs } from './args.ts';
12
+ export { exitCodeOf, formatReport } from './report.ts';
13
+ export {
14
+ type AdoptRow,
15
+ type NodeView,
16
+ type PlanView,
17
+ type TaskView,
18
+ changedFields,
19
+ rowsOf,
20
+ } from './rows.ts';
21
+ export {
22
+ type DiffAnswer,
23
+ type Observations,
24
+ type ReadAnswer,
25
+ type RecheckAnswer,
26
+ type Seen,
27
+ WRITE_REFUSED,
28
+ spyContext,
29
+ } from './spy.ts';
30
+ export {
31
+ type AdoptReport,
32
+ type VerifyOptions,
33
+ type VerifySession,
34
+ type VerifyTarget,
35
+ verifySession,
36
+ verifyStack,
37
+ } from './verify.ts';
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The scope Plan.ts gives every provider call it makes, for the calls the verifier makes itself
3
+ * after the plan: `--all`'s reads (verify.ts) and the recheck's diffs (recheck.ts).
4
+ *
5
+ * ⚠️ RE-CREATED, BECAUSE Plan.ts DOES NOT EXPORT IT (`providePlanScope`, alchemy beta.79): a scoped
6
+ * `Artifacts` bag over the run's `ArtifactStore` (a fresh one when none is provided) and the row's
7
+ * `InstanceId`. A kit family that consults either — the ownership helpers do — sees what it
8
+ * would see under `alchemy plan`. Moved here from verify.ts once a second caller needed it.
9
+ */
10
+ import {
11
+ ArtifactStore,
12
+ Artifacts,
13
+ createArtifactStore,
14
+ makeScopedArtifacts,
15
+ } from 'alchemy/Artifacts';
16
+ import { InstanceId } from 'alchemy/InstanceId';
17
+ import * as Effect from 'effect/Effect';
18
+ import * as Option from 'effect/Option';
19
+
20
+ export const inPlanScope =
21
+ (fqn: string, instanceId: string) =>
22
+ <A, E, R>(
23
+ effect: Effect.Effect<A, E, R>,
24
+ ): Effect.Effect<A, E, Exclude<R, Artifacts | InstanceId>> =>
25
+ Effect.gen(function* () {
26
+ const store = Option.getOrElse(
27
+ yield* Effect.serviceOption(ArtifactStore),
28
+ createArtifactStore,
29
+ );
30
+ return yield* effect.pipe(
31
+ Effect.provideService(Artifacts, makeScopedArtifacts(store, fqn)),
32
+ Effect.provideService(InstanceId, instanceId),
33
+ );
34
+ }) as Effect.Effect<A, E, Exclude<R, Artifacts | InstanceId>>;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * An adopted row whose provider's `diff` never looks at the live object (recheck.ts).
3
+ *
4
+ * 🔴 THE FALSE PASS THIS PINS (red-teamed 2026-09-21). Plan.ts hands an adopted row's diff
5
+ * `olds: news`, so a diff that compares recorded props with the declaration answers `noop`
6
+ * whatever the cloud holds. The verifier printed `ok` and exited 0 over a drift it had itself
7
+ * listed under `changed`, and the deploy then wrote it. The first test fails that way on the
8
+ * verifier without recheck.ts.
9
+ */
10
+ import { describe, expect, test } from 'bun:test';
11
+ import * as Effect from 'effect/Effect';
12
+ import { Recorded, Thing, cloudOf, fakeEngine, writesOf } from './fake-engine.ts';
13
+ import { exitCodeOf } from './report.ts';
14
+
15
+ const recorded = (name: string, comment: string) => Recorded(name, { comment, name });
16
+
17
+ describe('an adopted row whose diff compares recorded props', () => {
18
+ test('that drifted: asked again with the live value, it says update, and the row fails', async () => {
19
+ const cloud = cloudOf({ drifted: 'old' });
20
+ const engine = fakeEngine(cloud);
21
+ const report = await engine.verify(recorded('drifted', 'new'));
22
+ expect(report.rows).toEqual([
23
+ expect.objectContaining({
24
+ changed: ['comment'],
25
+ diff: 'noop',
26
+ ok: false,
27
+ planned: 'adopted',
28
+ recheck: 'update',
29
+ }),
30
+ ]);
31
+ expect(report.rows[0]?.why).toContain('recorded props');
32
+ expect(exitCodeOf(report)).toBe(1);
33
+ expect(writesOf(cloud)).toEqual([]);
34
+
35
+ // ★ And the verdict is the deploy's: the forced reconcile writes the drift the diff hid.
36
+ expect(await engine.deploy(recorded('drifted', 'new'))).toEqual({ drifted: 'adopted' });
37
+ expect(cloud.live.get('drifted')).toBe('new');
38
+ });
39
+
40
+ test('that matches: nothing differs, so it is not asked again and passes', async () => {
41
+ const cloud = cloudOf({ same: 'x' });
42
+ const report = await fakeEngine(cloud).verify(recorded('same', 'x'));
43
+ expect(report.rows[0]).toMatchObject({ changed: [], diff: 'noop', ok: true });
44
+ expect(report.rows[0]?.recheck).toBeUndefined();
45
+ expect(cloud.calls.filter((call) => call.startsWith('diff'))).toEqual(['diff same']);
46
+ });
47
+
48
+ test('a diff that reads the live object is not asked again when it already said update', async () => {
49
+ const cloud = cloudOf({ drifted: 'old' });
50
+ const report = await fakeEngine(cloud).verify(
51
+ Effect.all([Thing('drifted', { comment: 'new', name: 'drifted' })]),
52
+ );
53
+ expect(report.rows[0]).toMatchObject({ diff: 'update', ok: false });
54
+ expect(report.rows[0]?.recheck).toBeUndefined();
55
+ });
56
+ });
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Ask an adopted row's `diff` a second time, with the live values as its recorded props, when its
3
+ * first `noop` sits beside a read that differs from the declaration.
4
+ *
5
+ * 🔴 WHY (red-teamed 2026-09-21). Plan.ts hands an adopted row's diff `olds: news`, because the
6
+ * adopted state carries `props: news`. A diff that compares the RECORDED props with the
7
+ * declaration therefore answers `noop` whatever the cloud holds, and the forced reconcile then
8
+ * writes. Alchemy's own `Cloudflare.R2Bucket` diff is that shape (beta.79
9
+ * Cloudflare/R2/Bucket.ts, `olds.domains` against `news.domains`). The verifier said `ok`,
10
+ * exited 0, and listed the drift under `changed` on the same line. rows.ts already refused to
11
+ * trust a MISSING diff for this reason; a diff that never looks at the live object is the same
12
+ * blind spot one level down.
13
+ *
14
+ * ★ THE QUESTION IS "WOULD YOU STILL SAY noop IF STATE HAD RECORDED WHAT THE READ FOUND?" It is the
15
+ * planner's own input, replayed with one change: `olds` carries the read's value for each field
16
+ * in `changed`. A diff that reads the live object ignores `olds` and answers as before. Every kit
17
+ * PVE/PBS family re-reads (`pveOperations.diff`), so a field its `matches` leaves out, such as
18
+ * CephPool's autoscaled `pg_num`, still passes. A diff that compares `olds` now sees the drift.
19
+ *
20
+ * ⛔ ONLY `diff`, a read by Alchemy's contract, and through the WATCHED provider, so every write
21
+ * path still answers with spy.ts's refusal. The first answer is put back afterwards: the report's
22
+ * `diff` column stays what the planner heard.
23
+ * ⚠️ IT CAN ONLY TURN A PASS INTO A FAIL. It runs on a row that would otherwise pass (adopted,
24
+ * `noop`, something in `changed`), and anything but a second `noop`, a failure included, fails it.
25
+ * ⚠️ SAME-NAMED FIELDS ONLY, like `changed`: a drift in a field whose attribute has another name is
26
+ * invisible to both. Whether a `reconcile` PUTs identical values anyway is still up to the
27
+ * provider (docs/adopt-verify.md, Limits).
28
+ */
29
+ import type { ProviderService } from 'alchemy/Provider';
30
+ import * as Effect from 'effect/Effect';
31
+ import { inPlanScope } from './plan-scope.ts';
32
+ import { changedFields } from './rows.ts';
33
+ import { type Observations, type RecheckAnswer, diffAnswer } from './spy.ts';
34
+
35
+ /** The plan-node fields a recheck needs. */
36
+ export interface RecheckNode {
37
+ readonly action: string;
38
+ readonly provider?: ProviderService;
39
+ readonly state?: { readonly instanceId: string };
40
+ }
41
+
42
+ /** Recheck one planned row if it needs it; the answer lands in `seen` as `recheck`. */
43
+ export const recheck = (fqn: string, node: RecheckNode, seen: Observations): Effect.Effect<void> =>
44
+ Effect.gen(function* () {
45
+ const observed = seen.get(fqn);
46
+ const first = observed?.diff;
47
+ const input = first?.input;
48
+ const diff = node.provider?.diff;
49
+ if (node.action !== 'adopted' || first?.answer !== 'noop' || input === undefined) return;
50
+ const live = observed?.read?.attributes as Record<string, unknown> | undefined;
51
+ const changed = changedFields(input.news, live);
52
+ if (live === undefined || changed.length === 0) return;
53
+ if (diff === undefined || node.state === undefined) return;
54
+ const olds = {
55
+ ...(input.olds as object),
56
+ ...Object.fromEntries(changed.map((key) => [key, live[key]])),
57
+ };
58
+ // ⚠️ THE CAST IS THE ENGINE'S BOUNDARY, as in verify.ts: the diff's requirements are the
59
+ // session's, which verifySession provides around this call.
60
+ const asked = diff({ ...input, olds } as typeof input) as Effect.Effect<unknown>;
61
+ const answer: RecheckAnswer = yield* asked.pipe(
62
+ inPlanScope(fqn, node.state.instanceId),
63
+ Effect.map(diffAnswer),
64
+ Effect.catchCause(() => Effect.succeed('failed' as const)),
65
+ );
66
+ // The watched diff recorded the replay over the planner's answer; put the planner's back.
67
+ if (observed !== undefined) {
68
+ observed.diff = first;
69
+ observed.recheck = answer;
70
+ }
71
+ });