Files
apes-sidebar/tests/e2e-aggregate-auth.spec.ts
T
hairyf aae39e49ca fix(ci): isolate layout persistence, accept a detached HEAD, auth the aggregate lane
editor-host cases share one localStorage: setSession hydrates the previous case's layout for the same session id, so a persisted treeOpen:false decided whether the next case mounted its tree at all (the two Windows-lane failures). The file now clears it and the tree-seam call counters per test. smoke.spec asserted a branch name in a PR checkout, where HEAD is detached: it now compares git's own symbolic ref and status.detached. The aggregate lane exchanges its launch token for a signature cookie before probing /sidebar/api, because the plugin's native connection admission authenticates; the token is never echoed (redacted in the failure tail).
2026-10-13 23:13:07 +08:00

60 lines
2.4 KiB
TypeScript

import { spawnSync } from 'node:child_process'
import { mkdtempSync, readFileSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { expect, it } from 'vitest'
const root = fileURLToPath(new URL('../', import.meta.url)).replaceAll('\\', '/')
const script = readFileSync(join(root, 'scripts/e2e-aggregate-mount.sh'), 'utf8')
const hasBash = spawnSync('bash', ['--version'], { stdio: 'ignore' }).status === 0
it.skipIf(!hasBash)('exchanges the full aggregate launch URL and authenticates both unchanged API probes', () => {
const scratch = mkdtempSync(join(tmpdir(), 'dsh-aggregate-auth-')).replaceAll('\\', '/')
const launch = 'http://127.0.0.1:4199/?token=aggregate-test-token'
try {
expect(spawnSync('bash', ['-n', join(root, 'scripts/e2e-aggregate-mount.sh')]).status).toBe(0)
const start = script.indexOf('E2E_READY_RE=')
expect(start).toBeGreaterThan(-1)
const result = spawnSync('bash', ['-c', `
set -euo pipefail
E2E_TAG=e2e-aggregate-auth
source "$ROOT/scripts/e2e-common.sh"
OUT_LOG="$SCRATCH/out.log"
ERR_LOG="$SCRATCH/err.log"
printf 'dsh web: %s (LAN: http://example.invalid:4199)\\n' "$TEST_LAUNCH_URL" > "$OUT_LOG"
: > "$ERR_LOG"
SERVER_PID=$$
curl() {
printf '%s\\n' "$*" >> "$SCRATCH/curl.log"
case "\${!#}" in
"$TEST_LAUNCH_URL") : > "$SCRATCH/auth.cookies" ;;
*/settings.get) printf '%s' '{"ok":true}' ;;
*/__e2e_unknown__) printf '404' ;;
*) return 1 ;;
esac
}
${script.slice(start)}
`], {
encoding: 'utf8', timeout: 5_000,
env: { ...process.env, ROOT: root, SCRATCH: scratch, TEST_LAUNCH_URL: launch },
})
expect(result.stderr).toBe('')
expect(result.status).toBe(0)
expect(result.stdout).not.toContain('aggregate-test-token')
const calls = readFileSync(join(scratch, 'curl.log'), 'utf8').trim().split('\n')
expect(calls).toHaveLength(3)
expect(calls[0]).toContain(`--cookie-jar ${scratch}/auth.cookies`)
expect(calls[0]).toContain(launch)
expect(calls[0]).not.toMatch(/--location|-[^-\s]*L/)
for (const call of calls.slice(1)) {
expect(call).toContain(`--cookie ${scratch}/auth.cookies`)
expect(call).toContain('-X POST http://127.0.0.1:4199/sidebar/api/')
expect(call).not.toContain('?token=')
}
expect(result.stdout).toContain('HTTP 404')
} finally {
rmSync(scratch, { recursive: true, force: true })
}
})