Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions .github/scripts/batch-whitelist-ui.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Run from frontend/. The Vite dev server serves the real modal, locales and Tailwind styles.
import assert from 'node:assert/strict'
import { execFileSync } from 'node:child_process'
import { createHash } from 'node:crypto'
import { readFileSync, writeFileSync, rmSync, mkdirSync } from 'node:fs'
import { createRequire } from 'node:module'
import { resolve, join } from 'node:path'
import { pathToFileURL } from 'node:url'

const [mode, out] = process.argv.slice(2)
assert.ok(['before', 'after'].includes(mode) && out)
mkdirSync(out, { recursive: true })
const require = createRequire(resolve('package.json'))
const { createServer } = await import(pathToFileURL(require.resolve('vite').replace(/index\.cjs$/, 'dist/node/index.js')))
// Resolve the browser from an isolated installation, outside the application.
const { chromium } = createRequire(resolve(process.env.PLAYWRIGHT_ROOT, 'package.json'))('playwright')
const vue = require('@vitejs/plugin-vue')
const html = 'batch-whitelist-evidence.html'
const entry = 'batch-whitelist-evidence.js'
execFileSync('git', ['diff', '--quiet', 'HEAD', '--', 'src'])
const sha = execFileSync('git', ['rev-parse', 'HEAD'], { encoding: 'utf8' }).trim()
const manifest = { sha, mode, screenshots: [], fixture: 'Real BulkEditAccountModal and CSS. Synthetic admin, selected IDs and Axios adapter.' }
let browser, server
try {
writeFileSync(html, '<!doctype html><html lang="zh"><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><div id="app"></div><script type="module" src="./'+entry+'"></script></html>', { flag: 'wx' })
writeFileSync(entry, `
import {createApp, h} from 'vue'
import {createPinia} from 'pinia'
import Modal from './src/components/account/BulkEditAccountModal.vue'
import {i18n, loadLocaleMessages} from './src/i18n'
import {useAuthStore} from './src/stores/auth'
import {apiClient} from './src/api/client'
import './src/style.css'
await loadLocaleMessages('zh')
i18n.global.locale.value='zh'
window.calls=[]
window.requests=[]
apiClient.defaults.adapter=async config=>{
const url=config.url
window.requests.push({method:config.method,url})
if(config.method !== 'get' && !url.endsWith('/models/sync-upstream')) throw Error('Unexpected fixture write '+url)
let data={}
if(url.endsWith('/models/sync-upstream')){
window.calls.push(url)
data=url.includes('/42/') && window.calls.length===2 ? {models:[],skipped:'empty'} : {models:['synthetic'],applied:true,changed:true}
}
return {data:{code:0,data},status:200,statusText:'OK',headers:{},config}
}
const pinia=createPinia()
useAuthStore(pinia).user={id:9,role:'admin'}
createApp({render:()=>h(Modal,{show:true,accountIds:[41,42],selectedPlatforms:['anthropic'],selectedTypes:['apikey'],groups:[],proxies:[]})}).use(pinia).use(i18n).mount('#app')
`, { flag: 'wx' })
server = await createServer({ configFile: false, plugins: [vue()], cacheDir: join(out, 'vite-cache'),
resolve: { alias: { '@': resolve('src') } }, server: { host: '127.0.0.1', port: 0 } })
await server.listen()
browser = await chromium.launch()
for (const [name, viewport] of [['desktop',{width:1366,height:900}],['mobile',{width:390,height:844}]]) {
const page = await browser.newPage({viewport})
const errors = []
page.on('pageerror', e => errors.push(e.message))
await page.route('**/*', route => new URL(route.request().url()).hostname === '127.0.0.1' ? route.continue() : route.abort())
await page.goto(server.resolvedUrls.local[0] + html)
await page.locator('#bulk-edit-model-restriction-enabled').check()
const shared = page.getByRole('button', {name:'同步最新支持模型',exact:true})
const batch = page.getByRole('button', {name:'批量同步上游模型',exact:true})
assert.equal(await batch.count(), mode === 'after' ? 1 : 0)
const focus = mode === 'before' ? shared : batch
await focus.evaluate(el => el.scrollIntoView({block:'center',behavior:'instant'}))
await page.evaluate(async () => {
await document.fonts.ready
await Promise.all(document.getAnimations().filter(a=>a.effect.getTiming().iterations!==Infinity).map(a=>a.finished.catch(()=>{})))
})
if (mode === 'after') {
await batch.click()
await page.getByRole('button',{name:'仅重试失败账号'}).waitFor()
}
const box = await focus.boundingBox()
assert.ok(box && box.x >= 0 && box.x + box.width <= viewport.width && box.y > 0 && box.y + box.height < viewport.height)
assert.ok(await focus.evaluate(el => {
const b=el.getBoundingClientRect()
return el.contains(document.elementFromPoint(b.x+b.width/2,b.y+b.height/2))
}))
assert.deepEqual(errors, [])
const path = join(out, mode+'-'+name+'.png')
await page.screenshot({path})
if(mode === 'after') {
await page.getByRole('button',{name:'仅重试失败账号'}).click()
await page.waitForFunction(()=>window.calls.length===3)
assert.deepEqual(await page.evaluate(()=>window.calls),[41,42,42].map(id=>'/admin/accounts/'+id+'/models/sync-upstream'))
}
manifest.screenshots.push({name,viewport,box,sha256:createHash('sha256').update(readFileSync(path)).digest('hex'), requests:await page.evaluate(()=>window.requests)})
await page.close()
}
writeFileSync(join(out, mode+'-manifest.json'), JSON.stringify(manifest,null,2)+'\n')
} finally {
await browser?.close()
await server?.close()
rmSync(entry,{force:true})
rmSync(html,{force:true})
}
13 changes: 12 additions & 1 deletion .github/workflows/account-request-proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,24 @@ jobs:
test "$(git hash-object "$target")" = "$baseline_blob"
printf 'path=%s candidate_blob=%s restored_baseline_blob=%s\n' "$target" "$candidate_blob" "$baseline_blob" >> "$manifest"
done
# Restoring the token lifecycle above removes its later read-only
# whitelist helper. Pin only the dependent catalog caller to the
# exact pre-helper source; keep the original config-switch defects.
caller_baseline=add606e964972ded3d6389790586c781c89a58c1
target=backend/internal/service/openai_excel_bps_model_access.go
candidate_blob=$(git rev-parse "$candidate:$target")
test "$(git hash-object "$target")" = "$candidate_blob"
git show "$caller_baseline:$target" > "$target"
baseline_blob=$(git rev-parse "$caller_baseline:$target")
test "$(git hash-object "$target")" = "$baseline_blob"
printf 'compatibility_caller=%s baseline=%s candidate_blob=%s restored_baseline_blob=%s\n' "$target" "$caller_baseline" "$candidate_blob" "$baseline_blob" >> "$manifest"
for file in pr885_config_switch_refresh_test.go pr885_siwc_config_switch_test.go pr885_oauth_config_switch_test.go; do
target="backend/internal/service/$file"
blob=$(git rev-parse "$candidate:$target")
test "$(git hash-object "$target")" = "$blob"
printf 'unchanged_candidate_fixture=%s blob=%s\n' "$target" "$blob" >> "$manifest"
done
expected=$(printf '%s\n' backend/internal/service/openai_excel_oauth.go backend/internal/service/openai_maintenance_proxy.go backend/internal/service/openai_oauth_service.go backend/internal/service/openai_siwc.go backend/internal/service/openai_token_provider.go)
expected=$(printf '%s\n' backend/internal/service/openai_excel_bps_model_access.go backend/internal/service/openai_excel_oauth.go backend/internal/service/openai_maintenance_proxy.go backend/internal/service/openai_oauth_service.go backend/internal/service/openai_siwc.go backend/internal/service/openai_token_provider.go)
test "$(git diff --name-only -- 'backend/**/*.go' ':!backend/**/*_test.go')" = "$expected"
- name: Require all eight config switch failures to be behavioral
shell: bash
Expand Down
163 changes: 163 additions & 0 deletions .github/workflows/batch-upstream-whitelist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
name: Batch upstream whitelist
on:
pull_request:
paths:
- 'frontend/src/components/account/*UpstreamWhitelist*'
- 'frontend/src/composables/useBatchUpstreamWhitelist.ts'
- 'frontend/src/components/account/BulkEditAccountModal.vue'
- 'frontend/src/components/account/__tests__/BatchUpstreamWhitelist*'
- 'backend/internal/**/**batch_whitelist*'
- 'backend/internal/service/upstream_model_mapping_sync.go'
- 'backend/internal/service/upstream_models.go'
- 'backend/internal/service/openai_excel_bps_model_access.go'
- 'backend/internal/service/openai_models_list.go'
- 'backend/internal/service/openai_codex_models_service.go'
- 'backend/internal/service/openai_excel_oauth.go'
- 'backend/internal/handler/admin/account_handler.go'
- '.github/workflows/batch-upstream-whitelist.yml'
- '.github/scripts/batch-whitelist-ui.mjs'
permissions:
contents: read
concurrency:
group: batch-upstream-whitelist-${{ github.event.pull_request.number }}
cancel-in-progress: true
env:
BASE: 701612f6e9f7b697eb36397b9fb49bf7324e56a1
jobs:
contract:
runs-on: ubuntu-latest
timeout-minutes: 55
env:
CI: true
GOMAXPROCS: 4
GOFLAGS: -p=4
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- uses: actions/setup-go@v6
with:
go-version-file: backend/go.mod
cache-dependency-path: backend/go.sum
- name: Same handler oracle on baseline
shell: bash
run: |
set -euo pipefail
git worktree add --detach "$RUNNER_TEMP/before" "$BASE"
file=backend/internal/handler/admin/account_handler_batch_whitelist_test.go
cp "$file" "$RUNNER_TEMP/before/$file"
cd "$RUNNER_TEMP/before/backend"
if go test -v -tags=unit ./internal/handler/admin -run '^TestAccountHandlerBatchUpstreamWhitelist$' -count=1 > "$RUNNER_TEMP/handler-red.log" 2>&1; then exit 1; fi
cat "$RUNNER_TEMP/handler-red.log"
grep -F 'whitelist-only apply must not persist catalog metadata or quality state' "$RUNNER_TEMP/handler-red.log"
grep -F -- '--- FAIL: TestAccountHandlerBatchUpstreamWhitelist' "$RUNNER_TEMP/handler-red.log"
- name: Same incomplete-catalog oracle on baseline
shell: bash
run: |
set -euo pipefail
file=backend/internal/service/upstream_batch_whitelist_test.go
cp "$file" "$RUNNER_TEMP/before/$file"
cd "$RUNNER_TEMP/before/backend"
if go test -v -tags=unit ./internal/service -run 'TestBatchWhitelistSafety/unconsumed|TestBatchWhitelistBPSPartialCatalog' -count=1 > "$RUNNER_TEMP/catalog-red.log" 2>&1; then exit 1; fi
cat "$RUNNER_TEMP/catalog-red.log"
grep -F -- '--- FAIL: TestBatchWhitelistSafety/unconsumed' "$RUNNER_TEMP/catalog-red.log"
grep -F 'partial BPS/native catalogs cannot replace the entire whitelist' "$RUNNER_TEMP/catalog-red.log"
- name: Mapping-only fresh read and account state regression on reviewed head
shell: bash
run: |
set -euo pipefail
reviewed=add606e964972ded3d6389790586c781c89a58c1
git worktree add --detach "$RUNNER_TEMP/whitelist-read-before" "$reviewed"
file=backend/internal/service/upstream_batch_whitelist_read_policy_test.go
cp "$file" "$RUNNER_TEMP/whitelist-read-before/$file"
cd "$RUNNER_TEMP/whitelist-read-before/backend"
if go test -v -tags=unit ./internal/service -run '^TestBatchWhitelistBPS(NativeStructured401IsReadOnly|NativeStaleFailureKeepsMapping|NativeFreshCompleteSuccess|FreshCacheCannotHideFailure|ExpiredGrantDoesNotRefresh)$' -count=1 > "$RUNNER_TEMP/read-policy-red.log" 2>&1; then exit 1; fi
cat "$RUNNER_TEMP/read-policy-red.log"
grep -F 'whitelist discovery must not disable an account' "$RUNNER_TEMP/read-policy-red.log"
grep -F 'stale native cache cannot authorize a replacement whitelist' "$RUNNER_TEMP/read-policy-red.log"
grep -F 'BPS fresh cache must also be bypassed' "$RUNNER_TEMP/read-policy-red.log"
if grep -Eq 'build failed|setup failed|undefined:|no tests to run|panic:|WARNING: DATA RACE|--- SKIP:' "$RUNNER_TEMP/read-policy-red.log"; then exit 1; fi
- name: Candidate handler and catalog policies
working-directory: backend
run: |
set -o pipefail
go test -v -tags=unit ./internal/handler/admin ./internal/service ./internal/server/middleware -run 'Test(AccountHandler(Batch|SyncUpstreamModels)|BatchWhitelist|ApplyUpstreamModels|AutomaticUpstreamModels|FetchUpstreamSupportedModels|FetchOpenAIModelsList|FetchCodexModelsManifest(OAuth|AgentIdentity401|APIKey401)|SyncUpstreamModelCatalog|ReconciledUpstreamModels|ExcelBPSAccess|ExcelBPSMixed|ExcelOAuthRefresh|AdminAuth)' -count=1 | tee "$RUNNER_TEMP/handler-green.log"
- name: Build production server
run: make -C backend build
- name: PostgreSQL application, scheduler invalidation and stale edit protection
working-directory: backend
run: |
set -o pipefail
go test -v -tags=integration ./internal/repository ./internal/handler/admin -run '^Test(BatchWhitelistPostgresHandlerReadback|ApplyUpstreamModelsPreservesCredentialsAndInvalidatesScheduler)$' -count=1 | tee "$RUNNER_TEMP/postgres.log"
grep -F -- '--- PASS: TestBatchWhitelistPostgresHandlerReadback' "$RUNNER_TEMP/postgres.log"
grep -F -- '--- PASS: TestApplyUpstreamModelsPreservesCredentialsAndInvalidatesScheduler' "$RUNNER_TEMP/postgres.log"
- uses: actions/upload-artifact@v7
if: always()
with:
name: whitelist-contract-${{ github.event.pull_request.head.sha }}
path: |
${{ runner.temp }}/handler-red.log
${{ runner.temp }}/handler-green.log
${{ runner.temp }}/catalog-red.log
${{ runner.temp }}/read-policy-red.log
${{ runner.temp }}/postgres.log
browser:
runs-on: ubuntu-24.04
timeout-minutes: 35
env:
NODE_OPTIONS: --max-old-space-size=6144
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- uses: pnpm/action-setup@v6
with:
version: 9
- uses: actions/setup-node@v6
with:
node-version: 22
cache: pnpm
cache-dependency-path: frontend/pnpm-lock.yaml
- run: pnpm --dir frontend install --frozen-lockfile
- name: Mounted action before and after
shell: bash
run: |
set -euo pipefail
out="$RUNNER_TEMP/evidence"
mkdir -p "$out"
base="$RUNNER_TEMP/before"
git worktree add --detach "$base" "$BASE"
pnpm --dir "$base/frontend" install --frozen-lockfile
oracle=src/components/account/__tests__/BatchUpstreamWhitelist.spec.ts
cp "frontend/$oracle" "$base/frontend/$oracle"
if pnpm --dir "$base/frontend" exec vitest run "$oracle" -t 'submits each selected ID' > "$out/ui-red.log" 2>&1; then exit 1; fi
grep -F 'selected accounts need a per-account upstream action: expected false to be true' "$out/ui-red.log"
pnpm --dir frontend exec vitest run "$oracle" src/views/admin/__tests__/AccountsView.bulkEdit.spec.ts | tee "$out/ui-green.log"
- name: Install isolated Chromium
run: |
npm install --prefix "$RUNNER_TEMP/browser" --no-save --ignore-scripts playwright@1.56.1
"$RUNNER_TEMP/browser/node_modules/.bin/playwright" install --with-deps chromium
sudo apt-get install -y fonts-noto-cjk
- name: Render original and candidate components
env:
PLAYWRIGHT_ROOT: ${{ runner.temp }}/browser
run: |
script="$PWD/.github/scripts/batch-whitelist-ui.mjs"
(cd "$RUNNER_TEMP/before/frontend" && node "$script" before "$RUNNER_TEMP/evidence")
(cd frontend && node "$script" after "$RUNNER_TEMP/evidence")
- uses: actions/upload-artifact@v7
if: always()
with:
name: whitelist-ui-${{ github.event.pull_request.head.sha }}
path: |
${{ runner.temp }}/evidence/*.png
${{ runner.temp }}/evidence/*.json
${{ runner.temp }}/evidence/*.log
- name: Complete frontend CI (lint, typecheck, critical manifest)
run: make test-frontend
- name: Build production frontend
run: pnpm --dir frontend run build
env:
NODE_OPTIONS: --max-old-space-size=6144
18 changes: 17 additions & 1 deletion .github/workflows/issue715-agent-recovery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,31 @@ jobs:
original=6df0cd5bb0ce4d774d34004008f9dd661d236468
bash .github/scripts/historical-recovery-timezone-callers.sh
targets=(backend/internal/service/openai_codex_model_metadata.go backend/internal/service/openai_codex_models_service.go backend/internal/service/openai_excel_bps_models_manifest.go)
models_caller=backend/internal/service/openai_models_list.go
git fetch --no-tags --depth=1 origin "$original"
trap 'git restore --source=HEAD -- "${targets[@]}" backend/internal/service/openai_request_timezone_egress.go backend/internal/service/openai_ws_client.go; git diff --exit-code' EXIT
trap 'git restore --source=HEAD -- "${targets[@]}" "$models_caller" backend/internal/service/openai_request_timezone_egress.go backend/internal/service/openai_ws_client.go; git diff --exit-code' EXIT
git restore --source="$original" -- "${targets[@]}"
for target in "${targets[@]}"; do
expected=$(git rev-parse "$original:$target")
actual=$(git hash-object "$target")
echo "baseline=$original path=$target expected_blob=$expected tested_blob=$actual"
test "$expected" = "$actual"
done
# The historical manifest predates the whitelist-only policy API.
# Reconnect only its caller; retain candidate policy declarations and
# the exact historical capability implementation and test assertions.
python3 - "$models_caller" <<'PYTHON'
from pathlib import Path
import sys
path = Path(sys.argv[1])
source = path.read_text()
current = 's.fetchNativeCodexModelsManifestWithPolicy(ctx, account, clientVersion, "", policy)'
historical = 's.fetchNativeCodexModelsManifest(ctx, account, clientVersion, "")'
if source.count(current) != 1:
raise SystemExit("missing or ambiguous historical manifest caller")
path.write_text(source.replace(current, historical, 1))
PYTHON
echo "historical manifest compatibility caller path=$models_caller blob=$(git hash-object "$models_caller")"
set +e
(cd backend && go test -tags=unit ./internal/service -run '^TestIssue715(BridgeDoesNotAdvertiseEncryptedAgent|FetchedAndPinnedBridgeCapabilities|LiveBridgeCapabilityCannotOverrideWire)$' -count=1 -v -timeout=10m) > "$RUNNER_TEMP/issue715-red.log" 2>&1
result=$?
Expand Down
Loading
Loading