refactor(gateway): unify credential precedence across entrypoints
This commit is contained in:
@@ -47,7 +47,14 @@ describe("runServiceRestart token drift", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
runtimeLogs.length = 0;
|
||||
loadConfig.mockClear();
|
||||
loadConfig.mockReset();
|
||||
loadConfig.mockReturnValue({
|
||||
gateway: {
|
||||
auth: {
|
||||
token: "config-token",
|
||||
},
|
||||
},
|
||||
});
|
||||
service.isLoaded.mockClear();
|
||||
service.readCommand.mockClear();
|
||||
service.restart.mockClear();
|
||||
@@ -76,6 +83,32 @@ describe("runServiceRestart token drift", () => {
|
||||
expect(payload.warnings?.[0]).toContain("gateway install --force");
|
||||
});
|
||||
|
||||
it("uses env-first token precedence when checking drift", async () => {
|
||||
loadConfig.mockReturnValue({
|
||||
gateway: {
|
||||
auth: {
|
||||
token: "config-token",
|
||||
},
|
||||
},
|
||||
});
|
||||
service.readCommand.mockResolvedValue({
|
||||
environment: { OPENCLAW_GATEWAY_TOKEN: "env-token" },
|
||||
});
|
||||
vi.stubEnv("OPENCLAW_GATEWAY_TOKEN", "env-token");
|
||||
|
||||
await runServiceRestart({
|
||||
serviceNoun: "Gateway",
|
||||
service,
|
||||
renderStartHints: () => [],
|
||||
opts: { json: true },
|
||||
checkTokenDrift: true,
|
||||
});
|
||||
|
||||
const jsonLine = runtimeLogs.find((line) => line.trim().startsWith("{"));
|
||||
const payload = JSON.parse(jsonLine ?? "{}") as { warnings?: string[] };
|
||||
expect(payload.warnings).toBeUndefined();
|
||||
});
|
||||
|
||||
it("skips drift warning when disabled", async () => {
|
||||
await runServiceRestart({
|
||||
serviceNoun: "Node",
|
||||
|
||||
Reference in New Issue
Block a user