openclaw/scripts/lib/mac-node-worker-proof-state.mjs
Peter Steinberger dd4528b639
fix(macos): pair app builds with verified node workers (#131466)
Pair packaged apps with complete private arm64 and x86_64 workers whose full build identity matches the app. Preserve independently managed Gateways and complete recognized native-first state through the canonical initializer. Verify emitted-SDK filesystem calls, native capabilities, readiness and shutdown before app publication.

Derive elevation payloads without modifying canonical installed inputs. Preserve universal slices, resources and contained links; reject incomplete, malformed, escaping or mismatched payloads. Reuse descriptor-bound native inventory for signing while retaining the portable installer's independent distribution contract and every Foundation identity, entitlement, notarization and architecture gate.

Use the existing pinned-pnpm package path, including Corepack-only builders, and avoid recursive app-glob expansion. Centralize Mac CI ownership. Carry invocation-owned Git lock cleanup into main's canonical Git owner and regenerate its workflow projection, retaining lifetime fencing and pre-existing/junction-linked locks.

Fix the Android refresh race exposed by CI by removing the redundant reconnect after connect already replaces each role's socket. Preserve authentication, scopes and physical connection leases, with a controlled real-WebSocket regression.

Closes #131459
2026-08-29 14:47:55 -07:00

63 lines
1.9 KiB
JavaScript

import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { DatabaseSync } from "node:sqlite";
// Execute the native owner's literal DDL, not the full Node schema: package
// acceptance must reproduce the app-before-worker initialization order.
export function seedMacNodeWorkerProofState(databasePath) {
const source = fs.readFileSync(
new URL(
"../../apps/shared/OpenClawKit/Sources/OpenClawNativeState/OpenClawNativeStateSQLite.swift",
import.meta.url,
),
"utf8",
);
const statements = [...source.matchAll(/createSQL: """\n([\s\S]*?)\n\s*"""/gu)];
assert.equal(statements.length, 4, "Native bootstrap DDL must be extracted completely");
fs.mkdirSync(path.dirname(databasePath), { recursive: true });
const db = new DatabaseSync(databasePath);
try {
for (const [, sql] of statements) {
db.exec(sql);
}
db.prepare("INSERT INTO device_identities VALUES (?, ?, ?, ?, ?, ?)").run(
"node",
"synthetic-native-device",
"synthetic-public",
"synthetic-private",
1,
1,
);
db.prepare("INSERT INTO device_auth_tokens VALUES (?, ?, ?, ?, ?)").run(
"synthetic-native-device",
"node",
"synthetic-native-token",
"[]",
1,
);
db.prepare("INSERT INTO exec_approvals_config VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)").run(
"current",
'{"version":1,"defaults":{"security":"deny"},"agents":{}}',
null,
0,
"deny",
null,
null,
null,
0,
0,
1,
);
assert.equal(db.prepare("PRAGMA user_version").get().user_version, 0);
return readMacNodeWorkerProofRows(db);
} finally {
db.close();
}
}
export function readMacNodeWorkerProofRows(db) {
return ["device_identities", "device_auth_tokens", "exec_approvals_config"].map((table) =>
db.prepare(`SELECT * FROM ${table}`).all(),
);
}