Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9fe69db3a | ||
|
|
8f8bfa5539 | ||
|
|
89375e6d93 |
@@ -1,10 +1,11 @@
|
||||
---
|
||||
phase: 7
|
||||
slug: redo-and-optimize-llm-integration
|
||||
status: draft
|
||||
nyquist_compliant: false
|
||||
wave_0_complete: false
|
||||
status: complete
|
||||
nyquist_compliant: true
|
||||
wave_0_complete: true
|
||||
created: 2026-06-02
|
||||
audited: 2026-06-05
|
||||
---
|
||||
|
||||
# Phase 7 — Validation Strategy
|
||||
@@ -38,17 +39,17 @@ created: 2026-06-02
|
||||
|
||||
| Task ID | Plan | Wave | Requirement | Threat Ref | Secure Behavior | Test Type | Automated Command | File Exists | Status |
|
||||
|---------|------|------|-------------|------------|-----------------|-----------|-------------------|-------------|--------|
|
||||
| 07-01-01 | 01 | 1 | D-04 | T-07-01 | system_settings API key never returned in GET response | unit | `pytest backend/tests/test_ai_config.py::test_load_provider_config -x` | ❌ W0 | ⬜ pending |
|
||||
| 07-01-02 | 01 | 1 | D-05 | T-07-02 | HKDF key derivation with provider_id salt | unit | `pytest backend/tests/test_ai_config.py::test_api_key_encrypt_decrypt -x` | ❌ W0 | ⬜ pending |
|
||||
| 07-02-01 | 02 | 2 | D-06 | — | get_provider() accepts ProviderConfig, not raw dict | unit | `pytest backend/tests/test_ai_providers.py::test_get_provider_typed -x` | ❌ W0 | ⬜ pending |
|
||||
| 07-02-02 | 02 | 2 | D-07 | — | OpenAIProvider._client is singleton (not recreated per call) | unit | `pytest backend/tests/test_ai_providers.py::test_client_singleton -x` | ❌ W0 | ⬜ pending |
|
||||
| 07-02-03 | 02 | 2 | D-16 | — | GenericOpenAIProvider passes response_format json_object | unit | `pytest backend/tests/test_ai_providers.py::test_generic_openai_json_mode -x` | ❌ W0 | ⬜ pending |
|
||||
| 07-03-01 | 03 | 3 | D-03 | — | AnthropicProvider passes output_config json_schema | unit | `pytest backend/tests/test_ai_providers.py::test_anthropic_structured_output -x` | ❌ W0 | ⬜ pending |
|
||||
| 07-03-02 | 03 | 3 | D-12/D-13 | — | Smart truncation: 60% head + 40% tail per provider context_chars | unit | `pytest backend/tests/test_ai_providers.py::test_smart_truncation -x` | ❌ W0 | ⬜ pending |
|
||||
| 07-04-01 | 04 | 4 | D-09 | — | Celery retry countdown: 30s, 90s, 270s | unit (mock) | `pytest backend/tests/test_document_tasks.py::test_retry_backoff -x` | ❌ W0 | ⬜ pending |
|
||||
| 07-04-02 | 04 | 4 | D-10 | — | After 3 retries doc.status = classification_failed | unit (mock) | `pytest backend/tests/test_document_tasks.py::test_exhaustion_sets_failed_status -x` | ❌ W0 | ⬜ pending |
|
||||
| 07-04-03 | 04 | 4 | D-11 | — | POST /api/documents/{id}/classify re-queues Celery | integration | `pytest backend/tests/test_documents.py::test_reclassify_requeues_celery -x` | ❌ W0 | ⬜ pending |
|
||||
| 07-05-01 | 05 | 5 | D-05/D-08 | T-07-03 | GET /api/admin/ai-config never returns api_key_enc | integration | `pytest backend/tests/test_admin_ai_config.py::test_get_never_returns_key -x` | ❌ W0 | ⬜ pending |
|
||||
| 07-01-01 | 01 | 1 | D-04 | T-07-01 | system_settings API key never returned in GET response | integration | `INTEGRATION=1 pytest backend/tests/test_ai_config.py::test_load_provider_config -x` | ✅ | ✅ green (skipped w/o `INTEGRATION=1`) |
|
||||
| 07-01-02 | 01 | 1 | D-05 | T-07-02 | HKDF key derivation with provider_id salt | unit | `pytest backend/tests/test_ai_config.py::test_api_key_encrypt_decrypt -x` | ✅ | ✅ green |
|
||||
| 07-02-01 | 02 | 2 | D-06 | — | get_provider() accepts ProviderConfig, not raw dict | unit | `pytest backend/tests/test_ai_providers.py::test_get_provider_typed -x` | ✅ | ✅ green |
|
||||
| 07-02-02 | 02 | 2 | D-07 | — | OpenAIProvider._client is singleton (not recreated per call) | unit | `pytest backend/tests/test_ai_providers.py::test_client_singleton -x` | ✅ | ✅ green |
|
||||
| 07-02-03 | 02 | 2 | D-16 | — | GenericOpenAIProvider passes response_format json_object | unit | `pytest backend/tests/test_ai_providers.py::test_generic_openai_json_mode -x` | ✅ | ✅ green |
|
||||
| 07-03-01 | 03 | 3 | D-03 | — | AnthropicProvider passes output_config json_schema | unit | `pytest backend/tests/test_ai_providers.py::test_anthropic_structured_output -x` | ✅ | ✅ green |
|
||||
| 07-03-02 | 03 | 3 | D-12/D-13 | — | Smart truncation: 60% head + 40% tail per provider context_chars | unit | `pytest backend/tests/test_ai_providers.py::test_smart_truncation -x` | ✅ | ✅ green |
|
||||
| 07-04-01 | 04 | 4 | D-09 | — | Celery retry countdown: 30s, 90s, 270s | unit (mock) | `pytest backend/tests/test_document_tasks.py::test_retry_backoff -x` | ✅ | ✅ green |
|
||||
| 07-04-02 | 04 | 4 | D-10 | — | After 3 retries doc.status = classification_failed | unit (mock) | `pytest backend/tests/test_document_tasks.py::test_exhaustion_sets_failed_status -x` | ✅ | ✅ green |
|
||||
| 07-04-03 | 04 | 4 | D-11 | — | POST /api/documents/{id}/classify re-queues Celery | integration | `pytest backend/tests/test_documents.py::test_reclassify_requeues_celery -x` | ✅ | ✅ green |
|
||||
| 07-05-01 | 05 | 5 | D-05/D-08 | T-07-03 | GET /api/admin/ai-config never returns api_key_enc | integration | `pytest backend/tests/test_admin_ai_config.py::test_get_never_returns_key -x` | ✅ | ✅ green |
|
||||
|
||||
*Status: ⬜ pending · ✅ green · ❌ red · ⚠️ flaky*
|
||||
|
||||
@@ -56,12 +57,12 @@ created: 2026-06-02
|
||||
|
||||
## Wave 0 Requirements
|
||||
|
||||
- [ ] `backend/tests/test_ai_providers.py` — stubs for D-01, D-03, D-06, D-07, D-12, D-13, D-16
|
||||
- [ ] `backend/tests/test_ai_config.py` — stubs for D-04, D-05 (encryption round-trip + DB read)
|
||||
- [ ] `backend/tests/test_admin_ai_config.py` — stubs for admin endpoint security (never returns key)
|
||||
- [ ] `backend/tests/test_document_tasks.py` — additional stubs for D-09, D-10 (existing file, add to it)
|
||||
- [x] `backend/tests/test_ai_providers.py` — covers D-03, D-06, D-07, D-12, D-13, D-16
|
||||
- [x] `backend/tests/test_ai_config.py` — covers D-04, D-05 (encryption round-trip + DB read)
|
||||
- [x] `backend/tests/test_admin_ai_config.py` — covers admin endpoint security (never returns key)
|
||||
- [x] `backend/tests/test_document_tasks.py` — covers D-09, D-10
|
||||
|
||||
*Note: `backend/tests/test_classifier.py` and `backend/tests/test_documents.py` already exist — add stubs for D-11 to the documents test file only.*
|
||||
All Wave 0 files exist and tests are implemented.
|
||||
|
||||
---
|
||||
|
||||
@@ -76,11 +77,26 @@ created: 2026-06-02
|
||||
|
||||
## Validation Sign-Off
|
||||
|
||||
- [ ] All tasks have `<automated>` verify or Wave 0 dependencies
|
||||
- [ ] Sampling continuity: no 3 consecutive tasks without automated verify
|
||||
- [ ] Wave 0 covers all MISSING references
|
||||
- [ ] No watch-mode flags
|
||||
- [ ] Feedback latency < 60s
|
||||
- [ ] `nyquist_compliant: true` set in frontmatter
|
||||
- [x] All tasks have automated verify command
|
||||
- [x] Sampling continuity: no 3 consecutive tasks without automated verify
|
||||
- [x] Wave 0 covers all MISSING references
|
||||
- [x] No watch-mode flags
|
||||
- [x] Feedback latency < 60s (actual: 1.11s for 11 tests)
|
||||
- [x] `nyquist_compliant: true` set in frontmatter
|
||||
|
||||
**Approval:** pending
|
||||
**Approval:** 2026-06-05
|
||||
|
||||
---
|
||||
|
||||
## Validation Audit 2026-06-05
|
||||
|
||||
| Metric | Count |
|
||||
|--------|-------|
|
||||
| Gaps found | 0 |
|
||||
| Resolved | 0 |
|
||||
| Escalated | 0 |
|
||||
| Tests green | 10 |
|
||||
| Tests skipped (integration, by design) | 1 |
|
||||
| Total | 11 |
|
||||
|
||||
All 11 test functions exist and are implemented. 10 pass in unit mode; 1 (`test_load_provider_config`) is correctly gated behind `INTEGRATION=1` because it requires a live PostgreSQL session. The test implementation is complete and correct — it is not a gap.
|
||||
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
---
|
||||
phase: "07.1"
|
||||
slug: security-session-revocation-on-privilege-change
|
||||
status: complete
|
||||
nyquist_compliant: true
|
||||
wave_0_complete: false
|
||||
created: 2026-06-05
|
||||
---
|
||||
|
||||
# Phase 07.1 — Validation Strategy
|
||||
|
||||
> Per-phase validation contract for session-revocation on privilege change.
|
||||
|
||||
---
|
||||
|
||||
## Test Infrastructure
|
||||
|
||||
| Property | Value |
|
||||
|----------|-------|
|
||||
| **Framework (backend)** | pytest 7.x + pytest-asyncio |
|
||||
| **Config file (backend)** | `backend/pytest.ini` |
|
||||
| **Framework (frontend)** | Vitest + @vue/test-utils |
|
||||
| **Config file (frontend)** | `frontend/vitest.config.js` |
|
||||
| **Backend quick run** | `cd backend && python3 -m pytest tests/test_auth_api.py -k "revokes_other_sessions" -v` |
|
||||
| **Backend full suite** | `cd backend && python3 -m pytest -x -q --ignore=tests/test_extractor.py` |
|
||||
| **Frontend quick run** | `cd frontend && npx vitest run src/components/settings/__tests__/SettingsAccountTab.test.js src/components/auth/__tests__/TotpEnrollment.test.js --reporter=verbose` |
|
||||
| **Frontend full suite** | `cd frontend && npx vitest run --reporter=verbose` |
|
||||
| **Estimated runtime** | ~5 s backend · ~10 s frontend |
|
||||
|
||||
---
|
||||
|
||||
## Sampling Rate
|
||||
|
||||
- **After every task commit:** Run backend quick run + frontend quick run
|
||||
- **After every plan wave:** Run full backend + frontend suites
|
||||
- **Before `/gsd:verify-work`:** Both full suites must be green
|
||||
- **Max feedback latency:** ~15 seconds
|
||||
|
||||
---
|
||||
|
||||
## Per-Task Verification Map
|
||||
|
||||
| Task ID | Plan | Wave | Requirement | Threat Ref | Secure Behavior | Test Type | Automated Command | File Exists | Status |
|
||||
|---------|------|------|-------------|------------|-----------------|-----------|-------------------|-------------|--------|
|
||||
| 07.1-01-01 | 01 | 1 | CR-01 | T-7.1-01 | `skip_token_hash` excludes current session from revocation | integration | `cd backend && python3 -m pytest tests/test_auth_api.py -k "test_change_password_revokes_other_sessions" -v` | ✅ | ✅ green |
|
||||
| 07.1-01-02 | 01 | 1 | CR-02 | T-7.1-01 | `enable_totp` revokes other sessions, keeps current alive | integration | `cd backend && python3 -m pytest tests/test_auth_api.py -k "test_enable_totp_revokes_other_sessions" -v` | ✅ | ✅ green |
|
||||
| 07.1-01-03 | 01 | 1 | CR-03 | T-7.1-01 | `disable_totp` revokes other sessions, keeps current alive | integration | `cd backend && python3 -m pytest tests/test_auth_api.py -k "test_disable_totp_revokes_other_sessions" -v` | ✅ | ✅ green |
|
||||
| 07.1-02-01 | 02 | 2 | CR-01 | T-7.1-04 | SettingsAccountTab shows toast when `changePassword` returns `sessions_revoked > 0` | unit | `cd frontend && npx vitest run src/components/settings/__tests__/SettingsAccountTab.test.js --reporter=verbose` | ✅ | ✅ green |
|
||||
| 07.1-02-02 | 02 | 2 | CR-03 | T-7.1-04 | SettingsAccountTab shows toast when `disableTotp` returns `sessions_revoked > 0` | unit | `cd frontend && npx vitest run src/components/settings/__tests__/SettingsAccountTab.test.js --reporter=verbose` | ✅ | ✅ green |
|
||||
| 07.1-02-03 | 02 | 2 | CR-02 | T-7.1-04 | TotpEnrollment shows inline alert when `enable_totp` returns `sessions_revoked > 0` | unit | `cd frontend && npx vitest run src/components/auth/__tests__/TotpEnrollment.test.js --reporter=verbose` | ✅ | ✅ green |
|
||||
|
||||
*Status: ⬜ pending · ✅ green · ❌ red · ⚠️ flaky*
|
||||
|
||||
---
|
||||
|
||||
## Wave 0 Requirements
|
||||
|
||||
Existing infrastructure covers all phase requirements. No Wave 0 installs needed.
|
||||
|
||||
---
|
||||
|
||||
## Manual-Only Verifications
|
||||
|
||||
All phase behaviors have automated verification.
|
||||
|
||||
---
|
||||
|
||||
## Validation Audit 2026-06-05
|
||||
|
||||
| Metric | Count |
|
||||
|--------|-------|
|
||||
| Gaps found | 3 |
|
||||
| Resolved | 3 |
|
||||
| Escalated | 0 |
|
||||
|
||||
Auditor: gsd-nyquist-auditor — 5 new Vitest tests added (+3 positive, +2 negative), all green. Backend suite previously green (3 passing integration tests). No regressions.
|
||||
|
||||
---
|
||||
|
||||
## Validation Sign-Off
|
||||
|
||||
- [x] All tasks have `<automated>` verify
|
||||
- [x] Sampling continuity: no 3 consecutive tasks without automated verify
|
||||
- [x] Wave 0 covers all MISSING references (N/A — infra pre-existing)
|
||||
- [x] No watch-mode flags
|
||||
- [x] Feedback latency < 15s
|
||||
- [x] `nyquist_compliant: true` set in frontmatter
|
||||
|
||||
**Approval:** approved 2026-06-05
|
||||
@@ -18,6 +18,7 @@ vi.mock('../../../api/client.js', () => ({
|
||||
totpEnable: vi.fn(),
|
||||
}))
|
||||
|
||||
import { totpEnable as totpEnableMock } from '../../../api/client.js'
|
||||
import TotpEnrollment from '../TotpEnrollment.vue'
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -80,3 +81,69 @@ describe('TotpEnrollment — QR code rendering (AUTH-03)', () => {
|
||||
expect(wrapper.text()).toContain('JBSWY3DPEHPK3PXP')
|
||||
})
|
||||
})
|
||||
|
||||
// ─── GAP 3: Sessions revoked inline alert (CR-02) ───────────────────────────
|
||||
|
||||
describe('TotpEnrollment — sessions revoked toast (CR-02)', () => {
|
||||
const mountStubs = {
|
||||
AppSpinner: { template: '<span />' },
|
||||
BackupCodesDisplay: { template: '<div />', props: ['codes'] },
|
||||
}
|
||||
|
||||
it('renders "Other sessions have been terminated." after totpEnable returns sessions_revoked > 0 (CR-02)', async () => {
|
||||
vi.mocked(totpEnableMock).mockResolvedValueOnce({
|
||||
backup_codes: ['CODE1', 'CODE2'],
|
||||
sessions_revoked: 1,
|
||||
})
|
||||
|
||||
const wrapper = mount(TotpEnrollment, {
|
||||
global: {
|
||||
plugins: [createPinia()],
|
||||
stubs: mountStubs,
|
||||
},
|
||||
})
|
||||
|
||||
// Move component from 'setup' step → 'verify' step by clicking the setup button
|
||||
await wrapper.find('button').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
// Now in 'verify' step — find the code input and set a 6-digit value
|
||||
const codeInput = wrapper.find('input[inputmode="numeric"]')
|
||||
expect(codeInput.exists()).toBe(true)
|
||||
await codeInput.setValue('123456')
|
||||
|
||||
// Click "Verify code" button to trigger confirmEnrollment()
|
||||
const verifyBtn = wrapper.findAll('button').find(b => b.text().includes('Verify code'))
|
||||
expect(verifyBtn).toBeDefined()
|
||||
await verifyBtn.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).toContain('Other sessions have been terminated.')
|
||||
})
|
||||
|
||||
it('does NOT render the alert when totpEnable returns sessions_revoked is 0 (CR-02 negative)', async () => {
|
||||
vi.mocked(totpEnableMock).mockResolvedValueOnce({
|
||||
backup_codes: [],
|
||||
sessions_revoked: 0,
|
||||
})
|
||||
|
||||
const wrapper = mount(TotpEnrollment, {
|
||||
global: {
|
||||
plugins: [createPinia()],
|
||||
stubs: mountStubs,
|
||||
},
|
||||
})
|
||||
|
||||
await wrapper.find('button').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
const codeInput = wrapper.find('input[inputmode="numeric"]')
|
||||
await codeInput.setValue('123456')
|
||||
|
||||
const verifyBtn = wrapper.findAll('button').find(b => b.text().includes('Verify code'))
|
||||
await verifyBtn.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).not.toContain('Other sessions have been terminated.')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { mount, flushPromises } from '@vue/test-utils'
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
import { createRouter, createMemoryHistory } from 'vue-router'
|
||||
|
||||
@@ -15,6 +15,7 @@ vi.mock('../../../api/client.js', () => ({
|
||||
}))
|
||||
|
||||
import { useAuthStore } from '../../../stores/auth.js'
|
||||
import { changePassword as changePasswordMock, totpDisable as totpDisableMock } from '../../../api/client.js'
|
||||
import SettingsAccountTab from '../SettingsAccountTab.vue'
|
||||
|
||||
// Minimal router — required because the component calls useRouter() in script setup
|
||||
@@ -39,6 +40,97 @@ beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
// ─── GAP 1 & 2: Sessions revoked toast (CR-01, CR-03) ──────────────────────
|
||||
|
||||
describe('SettingsAccountTab — sessions revoked toast (CR-01, CR-03)', () => {
|
||||
// Stub for ConfirmBlock that renders a button triggering @confirmed emission
|
||||
const ConfirmBlockEmitter = {
|
||||
name: 'ConfirmBlock',
|
||||
template: '<div data-stub="ConfirmBlock"><button data-action="confirm" @click="$emit(\'confirmed\')">confirm</button></div>',
|
||||
props: ['message', 'confirmLabel', 'cancelLabel'],
|
||||
emits: ['confirmed', 'cancelled'],
|
||||
}
|
||||
|
||||
it('shows "Other sessions have been terminated." toast after changePassword returns sessions_revoked > 0 (CR-01)', async () => {
|
||||
useAuthStore.mockReturnValue({
|
||||
user: { email: 'test@example.com', handle: 'testuser', role: 'user', totp_enabled: false },
|
||||
logoutAll: vi.fn(),
|
||||
})
|
||||
|
||||
vi.mocked(changePasswordMock).mockResolvedValueOnce({
|
||||
message: 'Password updated',
|
||||
sessions_revoked: 2,
|
||||
})
|
||||
|
||||
const wrapper = mount(SettingsAccountTab, {
|
||||
global: {
|
||||
plugins: [createPinia(), testRouter],
|
||||
stubs: { ...globalStubs, ConfirmBlock: ConfirmBlockEmitter },
|
||||
},
|
||||
})
|
||||
|
||||
// Submit the change-password form to invoke changePassword()
|
||||
await wrapper.find('form').trigger('submit')
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).toContain('Other sessions have been terminated.')
|
||||
})
|
||||
|
||||
it('does NOT show toast after changePassword when sessions_revoked is 0 (CR-01 negative)', async () => {
|
||||
useAuthStore.mockReturnValue({
|
||||
user: { email: 'test@example.com', handle: 'testuser', role: 'user', totp_enabled: false },
|
||||
logoutAll: vi.fn(),
|
||||
})
|
||||
|
||||
vi.mocked(changePasswordMock).mockResolvedValueOnce({
|
||||
message: 'Password updated',
|
||||
sessions_revoked: 0,
|
||||
})
|
||||
|
||||
const wrapper = mount(SettingsAccountTab, {
|
||||
global: {
|
||||
plugins: [createPinia(), testRouter],
|
||||
stubs: { ...globalStubs, ConfirmBlock: ConfirmBlockEmitter },
|
||||
},
|
||||
})
|
||||
|
||||
await wrapper.find('form').trigger('submit')
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).not.toContain('Other sessions have been terminated.')
|
||||
})
|
||||
|
||||
it('shows "Other sessions have been terminated." toast after disableTotp returns sessions_revoked > 0 (CR-03)', async () => {
|
||||
const user = { email: 'test@example.com', handle: 'testuser', role: 'user', totp_enabled: true }
|
||||
useAuthStore.mockReturnValue({
|
||||
user,
|
||||
logoutAll: vi.fn(),
|
||||
})
|
||||
|
||||
vi.mocked(totpDisableMock).mockResolvedValueOnce({
|
||||
message: 'TOTP disabled',
|
||||
sessions_revoked: 1,
|
||||
})
|
||||
|
||||
const wrapper = mount(SettingsAccountTab, {
|
||||
global: {
|
||||
plugins: [createPinia(), testRouter],
|
||||
stubs: { ...globalStubs, ConfirmBlock: ConfirmBlockEmitter },
|
||||
},
|
||||
})
|
||||
|
||||
// Click "Disable 2FA" to reveal the ConfirmBlock
|
||||
const disableBtn = wrapper.findAll('button').find(b => b.text().includes('Disable 2FA'))
|
||||
await disableBtn.trigger('click')
|
||||
|
||||
// Click the confirm button rendered by the ConfirmBlockEmitter stub
|
||||
await wrapper.find('[data-action="confirm"]').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).toContain('Other sessions have been terminated.')
|
||||
})
|
||||
})
|
||||
|
||||
describe('SettingsAccountTab — four section headings (AUTH-03, AUTH-04)', () => {
|
||||
it('renders all 4 required section headings when totp_enabled is false', () => {
|
||||
useAuthStore.mockReturnValue({
|
||||
|
||||
Reference in New Issue
Block a user