Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/lib/actions/sandbox/launch-readiness-pairing-probe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,27 @@ it.each([
nextMode: "ui",
finalMode: "ui",
},
{
profile: "TUI after CLI pairing",
clientId: "openclaw-tui",
initialMode: "ui",
scopes: [...TUI_SCOPES, "operator.pairing"],
tokenScopes: [...TUI_SCOPES, "operator.pairing"],
authScopes: TUI_SCOPES,
nextMode: "ui",
finalMode: "ui",
},
])(
"keeps a published $profile lease accepted until its pairing state changes (#13100, #13668)",
async ({ clientId, initialMode, scopes, tokenScopes, nextMode, finalMode }) => {
async ({
clientId,
initialMode,
scopes,
tokenScopes,
authScopes = tokenScopes,
nextMode,
finalMode,
}) => {
const fixture = createOpenClawPairingFixture();
try {
const pairedPath = path.join(fixture.stateDirectory, "devices", "paired.json");
Expand All @@ -133,7 +151,7 @@ it.each([
fs.writeFileSync(pairedPath, JSON.stringify(paired));
const authPath = path.join(fixture.stateDirectory, "identity", "device-auth.json");
const auth = JSON.parse(fs.readFileSync(authPath, "utf8"));
auth.tokens.operator.scopes = [...tokenScopes];
auth.tokens.operator.scopes = [...authScopes];
fs.writeFileSync(authPath, JSON.stringify(auth));
let published: LaunchReadinessLease | null = null;
const deps: LaunchReadinessDeps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,14 +513,14 @@ describe("OpenClaw launch-readiness pairing qualification", () => {
],
authScopes: ["operator.admin", "operator.read", "operator.write"],
},
{
...[TUI_SCOPES, [...TUI_SCOPES, "operator.pairing"]].map((pairedScopes) => ({
clientId: "openclaw-tui",
clientMode: "ui",
pairedScopes: TUI_SCOPES,
pairedTokenScopes: TUI_SCOPES,
pairedScopes,
pairedTokenScopes: pairedScopes,
authScopes: TUI_SCOPES,
},
])("qualifies the exact persisted $clientId state", (profile) => {
})),
])("qualifies persisted $clientId with paired scopes $pairedScopes", (profile) => {
writeSqlitePairingState(stateDirectory, { deviceId, publicKey, privateKeyPem, ...profile });
expect(observe()).toMatchObject({ kind: "openclaw-pairing" });
expect(observeSettlement()).toMatchObject({ state: "settled" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ ADMIN_REQUEST_SCOPES = ['operator.admin', 'operator.pairing', 'operator.write']
ADMIN_PAIRED_TOKEN_SCOPES = ['operator.admin', 'operator.pairing', 'operator.read', 'operator.write']
ADMIN_AUTH_TOKEN_SCOPES = ['operator.admin', 'operator.read', 'operator.write']
TUI_SCOPES = ['operator.admin', 'operator.approvals', 'operator.read', 'operator.write']
TUI_SCOPES_WITH_PAIRING = [*TUI_SCOPES, 'operator.pairing']
ALLOW_CANONICAL_PENDING = ${mode === "ordinary-settlement" || mode === "repair-settlement" ? "True" : "False"}
ORDINARY_SETTLEMENT = ${mode === "ordinary-settlement" ? "True" : "False"}
REPORT_CANONICAL_PENDING = ${mode === "repair-settlement" ? "True" : "False"}
Expand Down Expand Up @@ -920,13 +921,15 @@ try:
and exact_string_set(paired_operator.get('scopes'), ADMIN_PAIRED_TOKEN_SCOPES)
and exact_string_set(auth_operator.get('scopes'), ADMIN_AUTH_TOKEN_SCOPES)
)
# The native TUI reuses the local device identity and records its own
# already-approved grants. Observe that exact settled profile without
# approving a pending request or changing either credential view.
tui_settled = tui_client and all(
exact_string_set(view, TUI_SCOPES) for view in (
paired_device.get('scopes'), paired_device.get('approvedScopes'),
paired_operator.get('scopes'), auth_operator.get('scopes'),
# After CLI pairing, the native TUI retains operator.pairing in all three
# server-side records. Its client credential still records only the TUI grant.
tui_server_scopes = (
TUI_SCOPES_WITH_PAIRING if exact_string_set(paired_device.get('scopes'), TUI_SCOPES_WITH_PAIRING)
else TUI_SCOPES
)
tui_settled = tui_client and exact_string_set(auth_operator.get('scopes'), TUI_SCOPES) and all(
exact_string_set(view, tui_server_scopes) for view in (
paired_device.get('scopes'), paired_device.get('approvedScopes'), paired_operator.get('scopes'),
)
)
settled = baseline_settled or admin_settled or tui_settled
Expand Down Expand Up @@ -981,8 +984,8 @@ try:
: "if not settled:\n reject()"
}

projected_request_scopes = TUI_SCOPES if tui_settled else ADMIN_REQUEST_SCOPES if admin_settled else (TOKEN_SCOPES if explicit_read_grant else REQUEST_SCOPES)
projected_paired_token_scopes = TUI_SCOPES if tui_settled else ADMIN_PAIRED_TOKEN_SCOPES if admin_settled else TOKEN_SCOPES
projected_request_scopes = tui_server_scopes if tui_settled else ADMIN_REQUEST_SCOPES if admin_settled else (TOKEN_SCOPES if explicit_read_grant else REQUEST_SCOPES)
projected_paired_token_scopes = tui_server_scopes if tui_settled else ADMIN_PAIRED_TOKEN_SCOPES if admin_settled else TOKEN_SCOPES
projected_auth_token_scopes = TUI_SCOPES if tui_settled else ADMIN_AUTH_TOKEN_SCOPES if admin_settled else TOKEN_SCOPES
projection = {
'deviceIdentitySha256': device_identity_sha256,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,44 @@ describe("readiness after a native OpenClaw TUI session", () => {
expect([fs.readFileSync(pairedPath), fs.readFileSync(authPath)]).toEqual(before);
});

function retainPairing() {
const device = paired[fixture.deviceId]!;
device.scopes.push("operator.pairing");
device.approvedScopes.push("operator.pairing");
device.tokens.operator.scopes.push("operator.pairing");
return device;
}

it("binds retained CLI pairing to the TUI receipt", () => {
const fresh = observe();
const device = retainPairing();
writeState();
const retained = observe();
expect(retained.deviceIdentitySha256).toBe(fresh.deviceIdentitySha256);
expect(retained.pairingStateSha256).not.toBe(fresh.pairingStateSha256);
device.scopes.reverse();
writeState();
expect(observe()).toEqual(retained);
});

it.each(["scopes", "approvedScopes", "token"] as const)(
"rejects a retained grant missing pairing from the server %s",
(key) => {
const device = retainPairing();
const scopes = key === "token" ? device.tokens.operator.scopes : device[key];
scopes.splice(scopes.indexOf("operator.pairing"), 1);
writeState();
expect(() => observe()).toThrow(OpenClawPairingQualificationError);
},
);

it("rejects retained pairing in the client grant", () => {
retainPairing();
auth.tokens.operator.scopes.push("operator.pairing");
writeState();
expect(() => observe()).toThrow(OpenClawPairingQualificationError);
});

it("binds the TUI grant in a stable digest distinct from the same CLI identity", () => {
const tuiReceipt = observe();
const device = paired[fixture.deviceId]!;
Expand Down
Loading