Files
houseplan-card/test/helpers/adoption-host.mjs
T
claude[bot] 7194fb2df0 feat(adoption): one owner for config/layout identity and the adoption sequence
`src/config-adoption.ts` owns config/layout with revision and fingerprint;
the host keeps `_serverCfg`/`_cfgRev`/`_layout`/`_layoutRev` as delegates.
All seven authoritative adoptions go through `adoptAuthoritativeGated`
(backdrop readiness → continuity → adopt → profile tail); the post-write
paths (space/delete ×2, optimize_undo, import/apply) gain the gate and take
revisions from the re-read bodies. `rollbackOptimistic` moves to the owner;
plan-optimize, space copy and the vacuum writers stop assigning identity.

Issue: #500
User-Visible: no
2026-09-10 11:41:16 +00:00

45 lines
1.7 KiB
JavaScript

// #500: test hosts mirror the card's delegation — identity lives in a real
// `ConfigAdoption`, the six host fields are accessors over it, bodies may be
// staged through the setters exactly as production code does.
import { createConfigAdoption } from '../../test-build/config-adoption.js';
/**
* Install `_adoption` and the delegating accessors on a plain host stub.
* `identity` seeds config/layout with revisions; fingerprints are computed.
*/
export function installAdoption(host, { config = null, layout = {}, configRev = 0, layoutRev = 0 } = {}) {
const adoption = createConfigAdoption();
if (config) {
adoption.restoreCached({ config, rev: configRev, layout, layout_rev: layoutRev });
} else {
adoption.stageLocalLayout(layout);
adoption.noteLayoutRevision(layoutRev);
}
Object.defineProperties(host, {
_adoption: { value: adoption, enumerable: true },
_serverCfg: {
get: () => adoption.config,
set: (next) => adoption.stageLocalConfig(next),
enumerable: true,
},
_layout: {
get: () => adoption.layout,
set: (next) => adoption.stageLocalLayout(next),
enumerable: true,
},
_cfgRev: { get: () => adoption.configRev, enumerable: true },
_layoutRev: { get: () => adoption.layoutRev, enumerable: true },
_cfgContentFingerprint: { get: () => adoption.configFingerprint, enumerable: true },
_layoutContentFingerprint: { get: () => adoption.layoutFingerprint, enumerable: true },
_rollbackOptimistic: {
value: (attempt) => {
const rolledBack = adoption.rollbackOptimistic(attempt);
if (rolledBack) host.requestUpdate?.();
return rolledBack;
},
enumerable: true,
},
});
return adoption;
}