import { expect, test } from '@playwright/test'; import { resolve } from 'node:path'; import { writeFile } from 'node:fs/promises'; import { subscriptionOperation } from './fixtures/subscriptionSession'; import type {} from '../physics/agent'; test.use({ trace: 'off', video: 'off' }); test('显式 opt-in:旧 v1 隔离订阅 API 兼容,非新版语言面板功能', async ({ page }, info) => { test.skip(process.env.LEKIWI_LIVE_SUBSCRIPTION !== '1', '需人工完成隔离官方登录;不使用全局账号'); const session = await subscriptionOperation('connect'); const connection = { address: String(session.address), token: String(session.token) }; try { expect(session.llmProtocol).toBe('codex'); expect((await subscriptionOperation('status')).loggedIn).toBe(true); await page.goto('/physics/agent.html'); await page.waitForFunction(() => Boolean(window.lekiwiAgent)); await page.evaluate( (url) => window.lekiwiAgent.boot(url), `/@fs${resolve('build/lekiwi/lekiwi-v1.zip')}`, ); const data = await page.evaluate((c) => window.lekiwiAgent.task(0, c), connection); const encoded = JSON.stringify(data, null, 2); if (encoded.includes(connection.token) || encoded.includes('auth.openai.com/')) throw new Error('证据包含认证信息'); await writeFile(info.outputPath('v1-subscription-evidence.json'), encoded); expect(data.state, data.error).toBe('succeeded'); expect(data.transported).toBeGreaterThanOrEqual(0.5); expect(data.receipts.find((r) => r.kind === 'plan')?.provider).toBe('codex'); const loggedOut = await page.evaluate(async (c) => { const response = await fetch(c.address + '/api/decision/v1/codex/logout', { method: 'POST', headers: { Authorization: 'Bearer ' + c.token, 'Content-Type': 'application/json' }, body: '{}', }); return response.ok; }, connection); expect(loggedOut).toBe(true); expect((await subscriptionOperation('status')).loggedIn).toBe(false); } catch (error) { await page.close().catch(() => undefined); // eslint-disable-next-line preserve-caught-error -- Avoid exposing private bridge tokens. throw new Error(String(error).replaceAll(connection.token, '[redacted]')); } });