重构 Grok SSO 上传到 webchat2api

This commit is contained in:
QLHazyCoder
2026-05-23 20:41:22 +08:00
parent f856910e5b
commit c649d43ee6
20 changed files with 957 additions and 97 deletions
+59 -5
View File
@@ -37,6 +37,12 @@ test('grok state view projects canonical runtime state into legacy flat read fie
cookies: ['cookie-a', 'cookie-b', 'cookie-a'],
extractedAt: 3000,
},
upload: {
status: 'uploaded',
uploadedAt: 4000,
message: 'ok',
targetUrl: 'https://remote.example.com/api/remote-account/inject',
},
},
},
},
@@ -55,9 +61,14 @@ test('grok state view projects canonical runtime state into legacy flat read fie
assert.equal(view.grokSsoCookie, 'cookie-a');
assert.deepEqual(view.grokSsoCookies, ['cookie-a', 'cookie-b']);
assert.equal(view.grokSsoExtractedAt, 3000);
assert.equal(view.grokWebchat2ApiUploadStatus, 'uploaded');
assert.equal(view.grokWebchat2ApiUploadedAt, 4000);
assert.equal(view.grokWebchat2ApiUploadMessage, 'ok');
assert.equal(view.grokWebchat2ApiTargetUrl, 'https://remote.example.com/api/remote-account/inject');
assert.equal(view.runtimeState.flowState.openai.preserved, true);
assert.equal(view.runtimeState.flowState.grok.register.email, 'user@example.com');
assert.equal(view.flowState.grok.sso.currentCookie, 'cookie-a');
assert.equal(view.flowState.grok.upload.status, 'uploaded');
assert.equal(view.flows.grok.sso.cookies.length, 2);
});
@@ -69,6 +80,10 @@ test('grok completion payloads update canonical runtime state and flat compatibi
grokSsoCookie: 'cookie-z',
grokSsoCookies: ['cookie-z', 'cookie-z', 'cookie-y'],
grokCompletedAt: 456,
grokWebchat2ApiUploadStatus: 'uploaded',
grokWebchat2ApiUploadedAt: 789,
grokWebchat2ApiUploadMessage: '上传成功',
grokWebchat2ApiTargetUrl: 'http://remote.example.com/api/remote-account/inject',
});
assert.equal(patch.grokEmail, 'grok@example.com');
@@ -77,11 +92,39 @@ test('grok completion payloads update canonical runtime state and flat compatibi
assert.deepEqual(patch.grokSsoCookies, ['cookie-z', 'cookie-y']);
assert.equal(patch.grokCompletedAt, 456);
assert.equal(patch.grokSsoExtractedAt, 456);
assert.equal(patch.grokWebchat2ApiUploadStatus, 'uploaded');
assert.equal(patch.grokWebchat2ApiUploadedAt, 789);
assert.equal(patch.grokWebchat2ApiUploadMessage, '上传成功');
assert.equal(patch.grokWebchat2ApiTargetUrl, 'http://remote.example.com/api/remote-account/inject');
assert.equal(patch.runtimeState.flowState.grok.register.email, 'grok@example.com');
assert.equal(patch.runtimeState.flowState.grok.sso.currentCookie, 'cookie-z');
assert.equal(patch.runtimeState.flowState.grok.upload.status, 'uploaded');
});
test('grok fresh keep-state reset preserves SSO cookies but clears registration runtime', () => {
test('grok state keeps canonical runtime values when flat compatibility fields are empty', () => {
const api = loadGrokStateApi();
const runtimeState = api.ensureRuntimeState({
grokSsoCookie: '',
grokSsoCookies: [],
runtimeState: {
flowState: {
grok: {
sso: {
currentCookie: 'canonical-cookie',
cookies: ['canonical-cookie'],
extractedAt: 1234,
},
},
},
},
});
assert.equal(runtimeState.sso.currentCookie, 'canonical-cookie');
assert.deepEqual(runtimeState.sso.cookies, ['canonical-cookie']);
assert.equal(runtimeState.sso.extractedAt, 1234);
});
test('grok fresh keep-state reset clears registration, SSO, and upload runtime', () => {
const api = loadGrokStateApi();
const patch = api.buildFreshKeepState({
runtimeState: {
@@ -101,6 +144,12 @@ test('grok fresh keep-state reset preserves SSO cookies but clears registration
cookies: ['cookie-a', 'cookie-b'],
extractedAt: 2000,
},
upload: {
status: 'uploaded',
uploadedAt: 3000,
message: 'ok',
targetUrl: 'https://remote.example.com/api/remote-account/inject',
},
},
},
},
@@ -111,11 +160,16 @@ test('grok fresh keep-state reset preserves SSO cookies but clears registration
assert.equal(patch.grokEmail, '');
assert.equal(patch.grokRegisterStatus, '');
assert.equal(patch.grokCompletedAt, 0);
assert.equal(patch.grokSsoCookie, 'cookie-a');
assert.deepEqual(patch.grokSsoCookies, ['cookie-a', 'cookie-b']);
assert.equal(patch.grokSsoExtractedAt, 2000);
assert.equal(patch.grokSsoCookie, '');
assert.deepEqual(patch.grokSsoCookies, []);
assert.equal(patch.grokSsoExtractedAt, 0);
assert.equal(patch.grokWebchat2ApiUploadStatus, '');
assert.equal(patch.grokWebchat2ApiUploadedAt, 0);
assert.equal(patch.grokWebchat2ApiUploadMessage, '');
assert.equal(patch.grokWebchat2ApiTargetUrl, '');
assert.equal(patch.runtimeState.flowState.grok.register.email, '');
assert.equal(patch.runtimeState.flowState.grok.sso.currentCookie, 'cookie-a');
assert.equal(patch.runtimeState.flowState.grok.sso.currentCookie, '');
assert.equal(patch.runtimeState.flowState.grok.upload.status, '');
});
test('grok downstream reset clears only the state owned by the restarted tail', () => {