Skip to content

Commit fb3d473

Browse files
authored
fix(nodes): preserve operator name on reapproval (#117608)
1 parent e9bd45d commit fb3d473

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

‎src/infra/node-pairing.test.ts‎

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ async function seedNodeDevice(baseDir: string, nodeId: string): Promise<void> {
3636
await approveDevicePairing(request.request.requestId, { callerScopes: [] }, baseDir);
3737
}
3838

39-
async function setupPairedNode(baseDir: string): Promise<void> {
39+
async function setupPairedNode(baseDir: string, displayName?: string): Promise<void> {
4040
await seedNodeDevice(baseDir, "node-1");
4141
const request = await requestNodePairing(
4242
{
4343
nodeId: "node-1",
44+
displayName,
4445
platform: "darwin",
4546
commands: ["system.run"],
4647
},
@@ -783,17 +784,50 @@ describe("node surface approvals", () => {
783784
});
784785
});
785786

786-
test("renames the operator-facing node name without touching approval state", async () => {
787+
test("keeps the operator-facing node name through capability reapproval", async () => {
787788
await withNodePairingDir(async (baseDir) => {
788-
await setupPairedNode(baseDir);
789+
await setupPairedNode(baseDir, "Reported iPad");
790+
const initialGeneration = resolveNodePairingGeneration(
791+
await getPairedDevice("node-1", baseDir),
792+
);
793+
if (!initialGeneration) {
794+
throw new Error("expected initial node pairing generation");
795+
}
796+
const upgrade = await requestNodePairing(
797+
{
798+
nodeId: "node-1",
799+
displayName: "Reported iPad (updated)",
800+
platform: "darwin",
801+
commands: ["system.run", "canvas.snapshot"],
802+
},
803+
baseDir,
804+
);
805+
expect(upgrade.request.displayName).toBe("Reported iPad (updated)");
789806

790807
const renamed = await renamePairedNode("node-1", "Living Room iPad", baseDir);
791808
expect(renamed?.displayName).toBe("Living Room iPad");
792809
await expect(renamePairedNode("missing", "Nope", baseDir)).resolves.toBeNull();
793810

811+
await expect(
812+
approveNodePairing(
813+
upgrade.request.requestId,
814+
{ callerScopes: ["operator.pairing", "operator.admin", "operator.write"] },
815+
baseDir,
816+
),
817+
).resolves.toMatchObject({
818+
node: {
819+
displayName: "Living Room iPad",
820+
commands: ["system.run", "canvas.snapshot"],
821+
},
822+
});
823+
794824
const pairedNode = await findPairedNode("node-1", baseDir);
795825
expect(pairedNode?.displayName).toBe("Living Room iPad");
796-
expect(pairedNode?.commands).toEqual(["system.run"]);
826+
expect(pairedNode?.commands).toEqual(["system.run", "canvas.snapshot"]);
827+
expect((await listNodePairing(baseDir)).pending).toEqual([]);
828+
expect(resolveNodePairingGeneration(await getPairedDevice("node-1", baseDir))?.key).not.toBe(
829+
initialGeneration.key,
830+
);
797831
});
798832
});
799833
});

‎src/infra/node-pairing.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,8 @@ export async function approveNodePairing(
569569
const previousPairingGeneration = resolveNodePairingGeneration(device);
570570
const now = Math.max(Date.now(), (device.nodeSurface?.approvedAtMs ?? -1) + 1);
571571
device.nodeSurface = {
572-
displayName: pending.displayName,
572+
// Reapproval refreshes the node-declared surface without replacing the operator-owned name.
573+
displayName: device.nodeSurface?.displayName ?? pending.displayName,
573574
version: pending.version,
574575
coreVersion: pending.coreVersion,
575576
uiVersion: pending.uiVersion,

0 commit comments

Comments
 (0)