Skip to content
Merged
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
70 changes: 70 additions & 0 deletions .github/scripts/encrypted-history-409-preview.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Render the production Vue setting with synthetic state. No external API.
import { mkdirSync, mkdtempSync, writeFileSync, unlinkSync, rmSync } from 'node:fs'
import { execFileSync } from 'node:child_process'
import { createRequire } from 'node:module'
import { tmpdir } from 'node:os'
import { dirname, join, resolve } from 'node:path'
import { pathToFileURL } from 'node:url'

const [repoArg, outputArg] = process.argv.slice(2)
if (!repoArg || !outputArg) throw Error('Usage: node encrypted-history-409-preview.mjs REPO OUTPUT')
const repo = resolve(repoArg), root = join(repo, 'frontend'), output = resolve(outputArg)
const require = createRequire(join(root, 'package.json'))
const { createServer } = await import(pathToFileURL(join(dirname(require.resolve('vite/package.json')), 'dist/node/index.js')).href)
const vue = (await import(pathToFileURL(require.resolve('@vitejs/plugin-vue')).href)).default
const { chromium } = await import(pathToFileURL(process.env.PLAYWRIGHT_MODULE).href)
const cache = mkdtempSync(join(tmpdir(), 'encrypted-history-409-'))
const entryName = `.encrypted-history-409-${process.pid}.js`, entry = join(root, entryName)
const origin = 'http://127.0.0.1:4297', errors = []
let server, browser
mkdirSync(output, { recursive: true })
try {
writeFileSync(entry, `
import {createApp,ref} from 'vue';
import {createPinia} from 'pinia';
import {i18n,loadLocaleMessages} from '/src/i18n/index.ts';
import Setting from '/src/components/settings/EncryptedHistory409Settings.vue';
import '/src/style.css';
const locale=new URL(location.href).searchParams.get('locale')||'zh';
await loadLocaleMessages(locale); i18n.global.locale.value=locale;
createApp({components:{Setting},setup(){return {enabled:ref(false)}},template:'<main class="mx-auto max-w-4xl p-8"><p class="mb-4 text-sm text-gray-500">System settings → Gateway · Actual component / fictional data</p><section class="card p-6"><Setting v-model="enabled" :user-id="99999" /></section></main>'}).use(createPinia()).use(i18n).mount('#app');
`, { flag: 'wx' })
process.chdir(root)
server = await createServer({ root, configFile: false, cacheDir: cache,
resolve: { alias: { '@': join(root, 'src'), vue: 'vue/dist/vue.esm-bundler.js' } },
plugins: [{ name: 'encrypted-history-preview', configureServer(s) {
s.middlewares.use((req, res, next) => {
if (req.url === '/' || req.url?.startsWith('/?')) {
res.setHeader('Content-Type', 'text/html')
res.end(`<!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="/${entryName}"></script></html>`)
} else if (req.url === '/favicon.ico') { res.statusCode = 204; res.end() } else next()
})
} }, vue()],
server: { host: '127.0.0.1', port: 4297, strictPort: true },
})
await server.listen()
browser = await chromium.launch({ headless: true })
const page = await browser.newPage({ viewport: { width: 1100, height: 620 } })
page.on('pageerror', e => errors.push(e.message))
await page.route('**/*', route => new URL(route.request().url()).origin === origin ? route.continue() : route.abort())
await page.goto(origin, { waitUntil: 'networkidle' })
const toggle = page.getByTestId('openai-409-omit-encrypted-history-toggle')
await toggle.waitFor()
await page.screenshot({ path: join(output, 'default-off.png'), fullPage: true, animations: 'disabled' })
await toggle.click()
await page.screenshot({ path: join(output, 'enabled.png'), fullPage: true, animations: 'disabled' })
await page.evaluate(() => document.documentElement.classList.add('dark'))
await page.setViewportSize({ width: 430, height: 700 })
await page.screenshot({ path: join(output, 'mobile-dark.png'), fullPage: true, animations: 'disabled' })
await page.setViewportSize({ width: 1100, height: 620 })
await page.goto(origin + '/?locale=en', { waitUntil: 'networkidle' })
await toggle.waitFor()
await page.screenshot({ path: join(output, 'english.png'), fullPage: true, animations: 'disabled' })
writeFileSync(join(output, 'manifest.json'), JSON.stringify({ source: execFileSync('git', ['rev-parse', 'HEAD'], { cwd: repo, encoding: 'utf8' }).trim(), boundary: 'Actual Vue setting component with fictional state; no full-page navigation, backend or production acceptance', errors }, null, 2))
if (errors.length) throw Error(errors.join('\n'))
} finally {
await browser?.close()
await server?.close()
unlinkSync(entry)
rmSync(cache, { recursive: true, force: true })
}
71 changes: 71 additions & 0 deletions .github/workflows/encrypted-history-409.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Encrypted history 409 Beta
on:
pull_request:
paths:
- 'backend/internal/service/openai_409_omit_history*'
- 'backend/internal/handler/openai_409_omit_history*'
- 'frontend/src/components/settings/EncryptedHistory409Settings.vue'
- '.github/scripts/encrypted-history-409-preview.mjs'
- '.github/workflows/encrypted-history-409.yml'
permissions:
contents: read
jobs:
protocol:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-go@v6
with:
go-version-file: backend/go.mod
cache-dependency-path: backend/go.sum
- name: Install isolated Redis fixture
run: |
bash .github/scripts/ci-ubuntu-mirrors.sh
if ! command -v redis-server >/dev/null; then
sudo apt-get update
sudo apt-get install -y --no-install-recommends redis-server
fi
- name: Actual HTTP and Redis omission regressions
working-directory: backend
shell: bash
run: |
set -euo pipefail
go test -race -tags=unit ./internal/service ./internal/handler ./internal/handler/admin -run '^Test(OmitOpenAIHistorical|OpenAI409|UpdateSettingsOpenAI409)' -count=1 -v -timeout=5m 2>&1 | tee "$RUNNER_TEMP/omit-history-protocol.log"
- uses: actions/upload-artifact@v7
if: always()
with:
name: encrypted-history-409-protocol-${{ github.event.pull_request.head.sha }}
path: ${{ runner.temp }}/omit-history-protocol.log
screenshots:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}
- 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: Install isolated screenshot browser
run: |
npm install --prefix "$RUNNER_TEMP/omit-history-browser" --no-save --ignore-scripts playwright@1.56.1
"$RUNNER_TEMP/omit-history-browser/node_modules/.bin/playwright" install --with-deps chromium
- name: Capture actual setting component
env:
PLAYWRIGHT_MODULE: ${{ runner.temp }}/omit-history-browser/node_modules/playwright/index.mjs
run: node .github/scripts/encrypted-history-409-preview.mjs "$GITHUB_WORKSPACE" "$RUNNER_TEMP/omit-history-ui"
- uses: actions/upload-artifact@v7
if: always()
with:
name: encrypted-history-409-ui-${{ github.event.pull_request.head.sha }}
path: ${{ runner.temp }}/omit-history-ui
if-no-files-found: error
8 changes: 5 additions & 3 deletions .github/workflows/issue715-agent-recovery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
git rev-parse HEAD
original=6df0cd5bb0ce4d774d34004008f9dd661d236468
targets=(backend/internal/handler/openai_gateway_handler.go backend/internal/service/openai_account_scheduler.go backend/internal/service/openai_gateway_forward.go backend/internal/service/openai_gateway_response_handling.go backend/internal/service/openai_gateway_service.go backend/internal/service/openai_ws_forwarder_ingress.go backend/internal/service/openai_ws_v2_passthrough_adapter.go backend/internal/service/openai_ws_http_bridge.go backend/internal/service/openai_ws_pool.go)
added=(backend/internal/service/openai_agent_message_recovery.go backend/internal/service/openai_agent_message_recovery_cache.go backend/internal/service/openai_agent_message_delivery.go backend/internal/repository/gateway_cache_agent_recovery.go backend/internal/service/openai_ws_agent_recovery.go backend/internal/service/openai_agent_message_recovery_wait.go backend/internal/service/openai_ws_search_activation.go)
added=(backend/internal/service/openai_agent_message_recovery.go backend/internal/service/openai_agent_message_recovery_cache.go backend/internal/service/openai_agent_message_delivery.go backend/internal/repository/gateway_cache_agent_recovery.go backend/internal/service/openai_ws_agent_recovery.go backend/internal/service/openai_agent_message_recovery_wait.go backend/internal/service/openai_ws_search_activation.go backend/internal/service/openai_409_omit_history.go)
# The exact original gateway struct predates analysis admission state.
# Pin this unrelated leaf to its pre-admission version, preserving all
# Issue715 business-chain blobs and the retained handler regressions.
Expand Down Expand Up @@ -243,18 +243,20 @@ jobs:
scheduler_compat=45e92f44470f91435bd261ea18111c271063c0ac
scheduler_leaf=backend/internal/service/openai_account_scheduler.go
wait_added=backend/internal/service/openai_agent_message_recovery_wait.go
# The Beta helper depends on fields absent in this historical recovery struct.
omission_added=backend/internal/service/openai_409_omit_history.go
git fetch --no-tags --depth=1 origin "$original"
git fetch --no-tags --depth=1 origin "$ws_original"
git fetch --no-tags --depth=1 origin "$scheduler_compat"
trap 'git restore --source=HEAD -- "${targets[@]}" "$added" "${ws_targets[@]}" "${ws_added[@]}" "$scheduler_leaf" "$wait_added"; git diff --exit-code' EXIT
trap 'git restore --source=HEAD -- "${targets[@]}" "$added" "${ws_targets[@]}" "${ws_added[@]}" "$scheduler_leaf" "$wait_added" "$omission_added"; git diff --exit-code' EXIT
git restore --source="$original" -- "${targets[@]}"
git restore --source="$ws_original" -- "${ws_targets[@]}"
git restore --source="$scheduler_compat" -- "$scheduler_leaf"
expected=$(git rev-parse "$scheduler_compat:$scheduler_leaf")
actual=$(git hash-object "$scheduler_leaf")
echo "compatibility_leaf_baseline=$scheduler_compat path=$scheduler_leaf expected_blob=$expected tested_blob=$actual"
test "$expected" = "$actual"
rm -- "$added" "${ws_added[@]}" "$wait_added"
rm -- "$added" "${ws_added[@]}" "$wait_added" "$omission_added"
test ! -e "$wait_added"
for target in "${targets[@]}"; do
expected=$(git rev-parse "$original:$target")
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/issue805-owner-policy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ jobs:
echo "$target test=baseline expected=$expected actual=$actual" >> "$RUNNER_TEMP/issue805-evidence/red-blobs.txt"
test "$expected" = "$actual"
done
# This later Beta test references a setting absent from the old production
# baseline. Exclude only this unrelated file in RED; GREEN retains it.
omission_test=backend/internal/handler/openai_409_omit_history_test.go
git cat-file -e "$EXPECTED_HEAD_SHA:$omission_test"
rm -- "$omission_test"
test ! -e "$omission_test"
echo "$omission_test test=candidate-only actual=absent" >> "$RUNNER_TEMP/issue805-evidence/red-blobs.txt"
# The selected regression and its shared harness must remain exact
# candidate blobs. The clean GREEN checkout retains all new tests.
for target in backend/internal/handler/openai_issue805_delivery_test.go backend/internal/handler/openai_issue805_owner_policy_test.go backend/internal/handler/openai_issue805_ws_test.go backend/internal/handler/openai_issue715_recovery_test.go; do
Expand Down
9 changes: 5 additions & 4 deletions backend/internal/handler/admin/setting_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,11 @@ func (h *SettingHandler) GetSettings(c *gin.Context) {
PrismBrowserBaseURL: settings.PrismBrowserBaseURL,
PrismBrowserAPIKeyConfigured: settings.PrismBrowserAPIKeyConfigured,

GrokDefaultTextModel: settings.GrokDefaultTextModel,
GrokCrossClientModelMapEnabled: settings.GrokCrossClientModelMapEnabled,
GrokDefaultBaseURLMode: settings.GrokDefaultBaseURLMode,
GrokVideoSourceURLEnabled: settings.GrokVideoSourceURLEnabled,
GrokDefaultTextModel: settings.GrokDefaultTextModel,
GrokCrossClientModelMapEnabled: settings.GrokCrossClientModelMapEnabled,
GrokDefaultBaseURLMode: settings.GrokDefaultBaseURLMode,
GrokVideoSourceURLEnabled: settings.GrokVideoSourceURLEnabled,
OpenAI409OmitEncryptedHistoryEnabled: settings.OpenAI409OmitEncryptedHistoryEnabled,

AvailableChannelsEnabled: settings.AvailableChannelsEnabled,
PelicanShowcaseEnabled: settings.PelicanShowcaseEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,24 @@ func TestUpdateSettingsGrokVideoSourceURLSwitchRoundTrips(t *testing.T) {
require.Equal(t, "false", repo.values[service.SettingKeyGrokVideoSourceURLEnabled])
}

func TestUpdateSettingsOpenAI409OmitEncryptedHistorySwitchRoundTrips(t *testing.T) {
h, repo := newStepUpSwitchTestHandler(t, map[string]string{
service.SettingKeyOpenAI409OmitEncryptedHistoryEnabled: "false",
})

rec := doUpdateSettings(t, h, map[string]any{"openai_409_omit_encrypted_history_enabled": true}, nil)
require.Equal(t, http.StatusOK, rec.Code)
require.Equal(t, "true", repo.values[service.SettingKeyOpenAI409OmitEncryptedHistoryEnabled])

rec = doUpdateSettings(t, h, map[string]any{"smtp_from_email": "other@example.com"}, nil)
require.Equal(t, http.StatusOK, rec.Code)
require.Equal(t, "true", repo.values[service.SettingKeyOpenAI409OmitEncryptedHistoryEnabled])

rec = doUpdateSettings(t, h, map[string]any{"openai_409_omit_encrypted_history_enabled": false}, nil)
require.Equal(t, http.StatusOK, rec.Code)
require.Equal(t, "false", repo.values[service.SettingKeyOpenAI409OmitEncryptedHistoryEnabled])
}

func TestUpdateSettingsRejectsTwoCaptchaProviders(t *testing.T) {
h, _ := newStepUpSwitchTestHandler(t, map[string]string{
service.SettingKeyTurnstileEnabled: "true",
Expand Down
24 changes: 16 additions & 8 deletions backend/internal/handler/admin/setting_handler_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,11 @@ type UpdateSettingsRequest struct {
ChannelMonitorHideUserRanking *bool `json:"channel_monitor_hide_user_ranking"`

// Grok model mapping policy
GrokDefaultTextModel *string `json:"grok_default_text_model"`
GrokCrossClientModelMapEnabled *bool `json:"grok_cross_client_model_map_enabled"`
GrokDefaultBaseURLMode *string `json:"grok_default_base_url_mode"`
GrokVideoSourceURLEnabled *bool `json:"grok_video_source_url_enabled"`
GrokDefaultTextModel *string `json:"grok_default_text_model"`
GrokCrossClientModelMapEnabled *bool `json:"grok_cross_client_model_map_enabled"`
GrokDefaultBaseURLMode *string `json:"grok_default_base_url_mode"`
GrokVideoSourceURLEnabled *bool `json:"grok_video_source_url_enabled"`
OpenAI409OmitEncryptedHistoryEnabled *bool `json:"openai_409_omit_encrypted_history_enabled"`

// Available Channels feature switch (user-facing)
AvailableChannelsEnabled *bool `json:"available_channels_enabled"`
Expand Down Expand Up @@ -2353,6 +2354,12 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
}
return previousSettings.GrokVideoSourceURLEnabled
}(),
OpenAI409OmitEncryptedHistoryEnabled: func() bool {
if req.OpenAI409OmitEncryptedHistoryEnabled != nil {
return *req.OpenAI409OmitEncryptedHistoryEnabled
}
return previousSettings.OpenAI409OmitEncryptedHistoryEnabled
}(),
AvailableChannelsEnabled: func() bool {
if req.AvailableChannelsEnabled != nil {
return *req.AvailableChannelsEnabled
Expand Down Expand Up @@ -2870,10 +2877,11 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
ChannelMonitorShowQuota: updatedSettings.ChannelMonitorShowQuota,
ChannelMonitorHideUserRanking: updatedSettings.ChannelMonitorHideUserRanking,

GrokDefaultTextModel: updatedSettings.GrokDefaultTextModel,
GrokCrossClientModelMapEnabled: updatedSettings.GrokCrossClientModelMapEnabled,
GrokDefaultBaseURLMode: updatedSettings.GrokDefaultBaseURLMode,
GrokVideoSourceURLEnabled: updatedSettings.GrokVideoSourceURLEnabled,
GrokDefaultTextModel: updatedSettings.GrokDefaultTextModel,
GrokCrossClientModelMapEnabled: updatedSettings.GrokCrossClientModelMapEnabled,
GrokDefaultBaseURLMode: updatedSettings.GrokDefaultBaseURLMode,
GrokVideoSourceURLEnabled: updatedSettings.GrokVideoSourceURLEnabled,
OpenAI409OmitEncryptedHistoryEnabled: updatedSettings.OpenAI409OmitEncryptedHistoryEnabled,

AvailableChannelsEnabled: updatedSettings.AvailableChannelsEnabled,
PelicanShowcaseEnabled: updatedSettings.PelicanShowcaseEnabled,
Expand Down
9 changes: 5 additions & 4 deletions backend/internal/handler/dto/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,11 @@ type SystemSettings struct {
ChannelMonitorHideUserRanking bool `json:"channel_monitor_hide_user_ranking"`

// Grok model mapping policy (admin settings; empty account mapping falls back to these).
GrokDefaultTextModel string `json:"grok_default_text_model"`
GrokCrossClientModelMapEnabled bool `json:"grok_cross_client_model_map_enabled"`
GrokDefaultBaseURLMode string `json:"grok_default_base_url_mode"`
GrokVideoSourceURLEnabled bool `json:"grok_video_source_url_enabled"`
GrokDefaultTextModel string `json:"grok_default_text_model"`
GrokCrossClientModelMapEnabled bool `json:"grok_cross_client_model_map_enabled"`
GrokDefaultBaseURLMode string `json:"grok_default_base_url_mode"`
GrokVideoSourceURLEnabled bool `json:"grok_video_source_url_enabled"`
OpenAI409OmitEncryptedHistoryEnabled bool `json:"openai_409_omit_encrypted_history_enabled"`

// Available Channels feature switch (user-facing aggregate view)
AvailableChannelsEnabled bool `json:"available_channels_enabled"`
Expand Down
Loading
Loading