feat(robot): enable guided hotspot binding by default

This commit is contained in:
2026-08-16 17:52:54 +08:00
parent 971865c256
commit b78fc07dba
3 changed files with 161 additions and 3 deletions

View File

@@ -65,7 +65,7 @@ async function invoke(handler: ReturnType<typeof createAiHardwareRouteHandler>,
}
describe('AI hardware Host API route', () => {
it('returns the default-off provisioning capability before credentials or upstream access', async () => {
it('returns the default-on provisioning capability before credentials or upstream access', async () => {
const { handler, fetchImpl, getAccessToken } = setup();
const result = await invoke(
handler,
@@ -73,6 +73,22 @@ describe('AI hardware Host API route', () => {
'/api/works/ai-hardware/provisioning-capabilities',
);
expect(result.payload).toEqual({
success: true,
data: { guided_hotspot_binding: true },
});
expect(getAccessToken).not.toHaveBeenCalled();
expect(fetchImpl).not.toHaveBeenCalled();
});
it('honors an explicitly injected disabled provisioning capability', async () => {
const { handler, fetchImpl, getAccessToken } = setup(undefined, { guidedHotspotBinding: false });
const result = await invoke(
handler,
'GET',
'/api/works/ai-hardware/provisioning-capabilities',
);
expect(result.payload).toEqual({
success: true,
data: { guided_hotspot_binding: false },
@@ -81,6 +97,36 @@ describe('AI hardware Host API route', () => {
expect(fetchImpl).not.toHaveBeenCalled();
});
it('honors the exact environment opt-out when Main loads the route', async () => {
vi.stubEnv('NIANCODE_AI_HARDWARE_GUIDED_HOTSPOT_BINDING', '0');
vi.resetModules();
try {
const { createAiHardwareRouteHandler: createHandlerWithEnv } = await import('@electron/api/routes/ai-hardware');
const fetchImpl = vi.fn<typeof fetch>().mockResolvedValue(jsonResponse(overview));
const getAccessToken = vi.fn().mockResolvedValue('secret-token');
const handler = createHandlerWithEnv({
fetchImpl,
getAccessToken,
apiBaseUrl: 'https://square.example',
});
const result = await invoke(
handler,
'GET',
'/api/works/ai-hardware/provisioning-capabilities',
);
expect(result.payload).toEqual({
success: true,
data: { guided_hotspot_binding: false },
});
expect(getAccessToken).not.toHaveBeenCalled();
expect(fetchImpl).not.toHaveBeenCalled();
} finally {
vi.unstubAllEnvs();
vi.resetModules();
}
});
it('rejects queried, body-bearing, and wrong-method capability requests locally', async () => {
const { handler, fetchImpl, getAccessToken } = setup();
const queried = await invoke(
@@ -129,7 +175,7 @@ describe('AI hardware Host API route', () => {
it('rejects disabled, expanded, or queried portal opens before invoking native or cloud dependencies', async () => {
const openExternal = vi.fn().mockResolvedValue(undefined);
const disabled = setup(undefined, { openExternal });
const disabled = setup(undefined, { guidedHotspotBinding: false, openExternal });
const disabledResult = await invoke(
disabled.handler,
'POST',