@conarium-ai/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +131 -0
- package/LICENSE +21 -0
- package/README.md +387 -0
- package/SECURITY.md +226 -0
- package/bin/conarium-anchor-service.mjs +77 -0
- package/bin/conarium-anchor-upgrade.mjs +108 -0
- package/bin/conarium-coverage.mjs +425 -0
- package/bin/conarium-doctor.mjs +480 -0
- package/bin/conarium-init.mjs +184 -0
- package/bin/conarium-reconcile.mjs +441 -0
- package/bin/conarium-stamp.mjs +161 -0
- package/bin/conarium-verify.mjs +610 -0
- package/conarium.config.json +43 -0
- package/deploy/anchor-service/README.md +79 -0
- package/deploy/anchor-service/conarium-anchor.service +21 -0
- package/deploy/anchor-service/dry-run.mjs +122 -0
- package/deploy/anchor-service/ecosystem.config.cjs +21 -0
- package/deploy/anchor-service/env.example +11 -0
- package/dist/anchor-service.d.ts +39 -0
- package/dist/anchor-service.d.ts.map +1 -0
- package/dist/anchor-service.js +278 -0
- package/dist/anchor-service.js.map +1 -0
- package/dist/anchor.d.ts +123 -0
- package/dist/anchor.d.ts.map +1 -0
- package/dist/anchor.js +246 -0
- package/dist/anchor.js.map +1 -0
- package/dist/audit-hash.d.ts +4 -0
- package/dist/audit-hash.d.ts.map +1 -0
- package/dist/audit-hash.js +12 -0
- package/dist/audit-hash.js.map +1 -0
- package/dist/audit.d.ts +104 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +391 -0
- package/dist/audit.js.map +1 -0
- package/dist/config.d.ts +273 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +44 -0
- package/dist/config.js.map +1 -0
- package/dist/connectors/docs.d.ts +23 -0
- package/dist/connectors/docs.d.ts.map +1 -0
- package/dist/connectors/docs.js +140 -0
- package/dist/connectors/docs.js.map +1 -0
- package/dist/connectors/index.d.ts +10 -0
- package/dist/connectors/index.d.ts.map +1 -0
- package/dist/connectors/index.js +37 -0
- package/dist/connectors/index.js.map +1 -0
- package/dist/connectors/jira.d.ts +16 -0
- package/dist/connectors/jira.d.ts.map +1 -0
- package/dist/connectors/jira.js +67 -0
- package/dist/connectors/jira.js.map +1 -0
- package/dist/connectors/openapi.d.ts +28 -0
- package/dist/connectors/openapi.d.ts.map +1 -0
- package/dist/connectors/openapi.js +447 -0
- package/dist/connectors/openapi.js.map +1 -0
- package/dist/connectors/postgres.d.ts +17 -0
- package/dist/connectors/postgres.d.ts.map +1 -0
- package/dist/connectors/postgres.js +131 -0
- package/dist/connectors/postgres.js.map +1 -0
- package/dist/connectors/slack.d.ts +16 -0
- package/dist/connectors/slack.d.ts.map +1 -0
- package/dist/connectors/slack.js +65 -0
- package/dist/connectors/slack.js.map +1 -0
- package/dist/connectors/supabase_rest.d.ts +35 -0
- package/dist/connectors/supabase_rest.d.ts.map +1 -0
- package/dist/connectors/supabase_rest.js +153 -0
- package/dist/connectors/supabase_rest.js.map +1 -0
- package/dist/connectors/zion.d.ts +24 -0
- package/dist/connectors/zion.d.ts.map +1 -0
- package/dist/connectors/zion.js +76 -0
- package/dist/connectors/zion.js.map +1 -0
- package/dist/console.d.ts +30 -0
- package/dist/console.d.ts.map +1 -0
- package/dist/console.js +257 -0
- package/dist/console.js.map +1 -0
- package/dist/coverage.d.ts +100 -0
- package/dist/coverage.d.ts.map +1 -0
- package/dist/coverage.js +175 -0
- package/dist/coverage.js.map +1 -0
- package/dist/executor.d.ts +12 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/executor.js +77 -0
- package/dist/executor.js.map +1 -0
- package/dist/governance.d.ts +124 -0
- package/dist/governance.d.ts.map +1 -0
- package/dist/governance.js +977 -0
- package/dist/governance.js.map +1 -0
- package/dist/http.d.ts +48 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +221 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/keys.d.ts +51 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +174 -0
- package/dist/keys.js.map +1 -0
- package/dist/license.d.ts +35 -0
- package/dist/license.d.ts.map +1 -0
- package/dist/license.js +122 -0
- package/dist/license.js.map +1 -0
- package/dist/llm-gate.d.ts +17 -0
- package/dist/llm-gate.d.ts.map +1 -0
- package/dist/llm-gate.js +19 -0
- package/dist/llm-gate.js.map +1 -0
- package/dist/openapi_connector.d.ts +6 -0
- package/dist/openapi_connector.d.ts.map +1 -0
- package/dist/openapi_connector.js +145 -0
- package/dist/openapi_connector.js.map +1 -0
- package/dist/pseudonymize.d.ts +19 -0
- package/dist/pseudonymize.d.ts.map +1 -0
- package/dist/pseudonymize.js +25 -0
- package/dist/pseudonymize.js.map +1 -0
- package/dist/rate_limit.d.ts +41 -0
- package/dist/rate_limit.d.ts.map +1 -0
- package/dist/rate_limit.js +66 -0
- package/dist/rate_limit.js.map +1 -0
- package/dist/receipt.d.ts +161 -0
- package/dist/receipt.d.ts.map +1 -0
- package/dist/receipt.js +210 -0
- package/dist/receipt.js.map +1 -0
- package/dist/scripts/discover_schema.d.ts +2 -0
- package/dist/scripts/discover_schema.d.ts.map +1 -0
- package/dist/scripts/discover_schema.js +75 -0
- package/dist/scripts/discover_schema.js.map +1 -0
- package/dist/scripts/dogfood_prove.d.ts +2 -0
- package/dist/scripts/dogfood_prove.d.ts.map +1 -0
- package/dist/scripts/dogfood_prove.js +41 -0
- package/dist/scripts/dogfood_prove.js.map +1 -0
- package/dist/search_policy.d.ts +23 -0
- package/dist/search_policy.d.ts.map +1 -0
- package/dist/search_policy.js +79 -0
- package/dist/search_policy.js.map +1 -0
- package/dist/server.d.ts +29 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +379 -0
- package/dist/server.js.map +1 -0
- package/dist/tokens.d.ts +14 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +58 -0
- package/dist/tokens.js.map +1 -0
- package/dist/types.d.ts +132 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/docs/ARCHITECTURE.md +42 -0
- package/docs/CONSENT-BINDING-SPEC.md +136 -0
- package/docs/CONSENT-BINDING-SPEC.md.anchors.jsonl +1 -0
- package/docs/PRIOR-ART.md +213 -0
- package/docs/PRIOR-ART.md.anchors.jsonl +3 -0
- package/docs/RECEIPT-SPEC.md +301 -0
- package/docs/RECEIPT-SPEC.md.anchors.jsonl +1 -0
- package/docs/dogfood/2026-07-31-anchor.anchors.jsonl +1 -0
- package/docs/dogfood/2026-08-06-reconcile.md +140 -0
- package/docs/plans/2026-07-02-redteam-harness.md +416 -0
- package/docs/specs/2026-07-02-redteam-harness-design.md +90 -0
- package/docs/superpowers/TODO-gate1-f4.md +23 -0
- package/docs/superpowers/plans/2026-07-29-conarium-receipt-plan.md +200 -0
- package/docs/superpowers/plans/2026-07-29-katman0-kapanis-plan.md +231 -0
- package/docs/superpowers/plans/2026-07-31-per-user-identity.md +667 -0
- package/docs/superpowers/specs/2026-07-29-conarium-receipt-design.md +202 -0
- package/docs/superpowers/specs/2026-07-31-per-user-identity-design.md +144 -0
- package/docs/superpowers/specs/2026-08-01-coverage-proof-design.md +139 -0
- package/docs/superpowers/specs/2026-08-05-receipt-meta-provenance-design.md +116 -0
- package/examples/claude-desktop-config.json +9 -0
- package/examples/cursor-mcp-settings.json +10 -0
- package/package.json +99 -0
- package/scripts/audit-chain-check.mjs +119 -0
- package/scripts/conarium_sabah_brief.mjs +107 -0
- package/scripts/gen-test-vectors.mjs +193 -0
- package/scripts/pg-snapshot.sql +27 -0
- package/scripts/start-mcp-c1.mjs +70 -0
- package/test-vectors/001-single-receipt/receipts.jsonl +1 -0
- package/test-vectors/002-chain-of-three/receipts.jsonl +3 -0
- package/test-vectors/003-tampered-field/receipts.jsonl +1 -0
- package/test-vectors/004-prevhash-break/receipts.jsonl +2 -0
- package/test-vectors/005-seq-gap/receipts.jsonl +2 -0
- package/test-vectors/006-bad-signature/receipts.jsonl +1 -0
- package/test-vectors/007-schema-invalid/receipts.jsonl +1 -0
- package/test-vectors/008-unsigned-no-pubkey/receipts.jsonl +1 -0
- package/test-vectors/009-unsigned-but-pubkey-given/receipts.jsonl +1 -0
- package/test-vectors/README.md +92 -0
- package/test-vectors/expected-hashes.json +24 -0
- package/test-vectors/keys/vector-key.SECRET-TEST-ONLY.pem +6 -0
- package/test-vectors/keys/vector-key.pub.pem +3 -0
- package/test-vectors/keys/vector-key.pub.pem.keyid +1 -0
- package/test-vectors/manifest.json +95 -0
|
@@ -0,0 +1,667 @@
|
|
|
1
|
+
# Kişi Bazlı Kimlik — Uygulama Planı
|
|
2
|
+
|
|
3
|
+
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
|
4
|
+
|
|
5
|
+
**Goal:** Conarium'un denetim kaydı ve makbuzu, erişimi yapan **kişiyi** adıyla kaydetsin — kimliği doğrulanmış bir kaynaktan alarak, ve bu kimliğin nasıl kurulduğunu artefaktın içinde beyan ederek.
|
|
6
|
+
|
|
7
|
+
**Architecture:** Ortak bir token deposu (`src/tokens.ts`) gelen token'ı karmalayıp kişiye çözer. Bu kimlik iki yüzeye akar: canlı denetim kaydı (`src/audit.ts`) ve makbuz (`src/receipt.ts`, v0.2). Doğrulayıcı iki makbuz sürümünü de kabul eder. Token dosyası yoksa hiçbir davranış değişmez.
|
|
8
|
+
|
|
9
|
+
**Tech Stack:** TypeScript (ESM, NodeNext), Vitest, Node `crypto` (sha256, timingSafeEqual). Yeni bağımlılık **yok**.
|
|
10
|
+
|
|
11
|
+
## Global Constraints
|
|
12
|
+
|
|
13
|
+
- Tasarım kaynağı: `docs/superpowers/specs/2026-07-31-per-user-identity-design.md`. Çelişki olursa spec kazanır.
|
|
14
|
+
- Kod stili: **noktalı virgül yok**, tek tırnak, 2 boşluk girinti — mevcut `src/*.ts` ile aynı.
|
|
15
|
+
- `type: 'user'` **yalnızca** kişiye özel token eşleştiğinde yazılır. Tahmin/çıkarım yasak.
|
|
16
|
+
- Token dosyası **düz metin token içermez**, yalnızca SHA-256 karması.
|
|
17
|
+
- Token dosyası yoksa davranış bugünküyle **birebir** aynı olmalı (v0.1 makbuz, `service` aktör).
|
|
18
|
+
- `RECEIPT_VERSION` iki yerde tanımlı: `src/receipt.ts:8` ve `bin/conarium-verify.mjs:28`. İkisi birlikte güncellenir.
|
|
19
|
+
- v0.1 makbuzları **sonsuza kadar** doğrulanabilir kalır. Bu bir regresyon testiyle korunur.
|
|
20
|
+
- Her görev sonunda `npm test` tamamen yeşil olmalı (bugün 92/92).
|
|
21
|
+
- İddia güncellemesi (`compare.html`, `llms.txt`, `RECEIPT-SPEC`) bu planın **dışındadır** ve kod gönderildikten **sonra** yapılır.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
### Task 1: Token deposu
|
|
26
|
+
|
|
27
|
+
Kimliğin tek kaynağı. Diğer iki görev buna dayanır.
|
|
28
|
+
|
|
29
|
+
**Files:**
|
|
30
|
+
- Create: `src/tokens.ts`
|
|
31
|
+
- Test: `src/tokens.test.ts`
|
|
32
|
+
|
|
33
|
+
**Interfaces:**
|
|
34
|
+
- Consumes: yok (temel taş).
|
|
35
|
+
- Produces:
|
|
36
|
+
- `export type ActorAssurance = 'shared-token' | 'per-user-token'`
|
|
37
|
+
- `export interface ResolvedActor { id: string; assurance: ActorAssurance; isUser: boolean }`
|
|
38
|
+
- `export function loadTokenStore(path?: string): Map<string, string> | null` — karma → kişi id haritası; dosya yoksa `null`
|
|
39
|
+
- `export function resolveActor(supplied: string, store: Map<string, string> | null, fallbackId: string): ResolvedActor`
|
|
40
|
+
|
|
41
|
+
- [x] **Step 1: Testi yaz (kırmızı)**
|
|
42
|
+
|
|
43
|
+
`src/tokens.test.ts`:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { describe, it, expect } from 'vitest'
|
|
47
|
+
import { createHash } from 'node:crypto'
|
|
48
|
+
import { mkdtempSync, writeFileSync } from 'node:fs'
|
|
49
|
+
import { join } from 'node:path'
|
|
50
|
+
import { tmpdir } from 'node:os'
|
|
51
|
+
import { loadTokenStore, resolveActor } from './tokens.js'
|
|
52
|
+
|
|
53
|
+
function tokenFile(entries: { token: string; id: string }[]): string {
|
|
54
|
+
const dir = mkdtempSync(join(tmpdir(), 'cnr-tok-'))
|
|
55
|
+
const p = join(dir, 'conarium.tokens.json')
|
|
56
|
+
writeFileSync(p, JSON.stringify({
|
|
57
|
+
tokens: entries.map(e => ({
|
|
58
|
+
sha256: createHash('sha256').update(e.token).digest('hex'),
|
|
59
|
+
id: e.id,
|
|
60
|
+
})),
|
|
61
|
+
}))
|
|
62
|
+
return p
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
describe('token deposu', () => {
|
|
66
|
+
it('dosya yoksa null döner — kişi bazlı kimlik kapalıdır, hata değil', () => {
|
|
67
|
+
expect(loadTokenStore(join(tmpdir(), 'cnr-yok-' + Date.now() + '.json'))).toBeNull()
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('eşleşen token kişiyi çözer ve per-user-token olarak işaretler', () => {
|
|
71
|
+
const store = loadTokenStore(tokenFile([{ token: 'tok-ayse', id: 'ayse@sirket.com' }]))
|
|
72
|
+
const a = resolveActor('tok-ayse', store, 'conarium_c2')
|
|
73
|
+
expect(a).toEqual({ id: 'ayse@sirket.com', assurance: 'per-user-token', isUser: true })
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('depo yokken paylaşılan token servis kimliğine düşer', () => {
|
|
77
|
+
const a = resolveActor('paylasilan', null, 'conarium_c2')
|
|
78
|
+
expect(a).toEqual({ id: 'conarium_c2', assurance: 'shared-token', isUser: false })
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('depo VARKEN eşleşmeyen token kişi kimliği ÜRETMEZ', () => {
|
|
82
|
+
const store = loadTokenStore(tokenFile([{ token: 'tok-ayse', id: 'ayse@sirket.com' }]))
|
|
83
|
+
const a = resolveActor('baska-token', store, 'conarium_c2')
|
|
84
|
+
expect(a.isUser).toBe(false)
|
|
85
|
+
expect(a.assurance).toBe('shared-token')
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('depo dosyasında düz metin token bulunmaz', () => {
|
|
89
|
+
const p = tokenFile([{ token: 'gizli-token-123', id: 'ayse@sirket.com' }])
|
|
90
|
+
const ham = readFileSync(p, 'utf8')
|
|
91
|
+
expect(ham).not.toContain('gizli-token-123')
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`readFileSync`'i import listesine ekle: `import { mkdtempSync, writeFileSync, readFileSync } from 'node:fs'`.
|
|
97
|
+
|
|
98
|
+
- [x] **Step 2: Kırmızıyı doğrula**
|
|
99
|
+
|
|
100
|
+
Çalıştır: `npx vitest run src/tokens.test.ts`
|
|
101
|
+
Beklenen: FAIL — `Cannot find module './tokens.js'`
|
|
102
|
+
|
|
103
|
+
- [x] **Step 3: Asgari uygulamayı yaz**
|
|
104
|
+
|
|
105
|
+
`src/tokens.ts`:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
/**
|
|
109
|
+
* Kişi bazlı kimlik — token deposu.
|
|
110
|
+
*
|
|
111
|
+
* Neden beyan değil token: istemcinin gönderdiği isim (X-Conarium-Actor gibi)
|
|
112
|
+
* kimse tarafından doğrulanmamıştır; onu imzalayıp makbuza yazmak, dürüst
|
|
113
|
+
* 'service' değerinden kötüdür. Token'ı Conarium zaten doğruluyor, dolayısıyla
|
|
114
|
+
* kimin bağlandığını BİLİR.
|
|
115
|
+
*
|
|
116
|
+
* Token'lar düz metin saklanmaz — yalnızca SHA-256 karması. Dosya sızsa bile
|
|
117
|
+
* kimsenin token'ı ele geçmez.
|
|
118
|
+
*/
|
|
119
|
+
import { createHash } from 'node:crypto'
|
|
120
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
121
|
+
|
|
122
|
+
export type ActorAssurance = 'shared-token' | 'per-user-token'
|
|
123
|
+
|
|
124
|
+
export interface ResolvedActor {
|
|
125
|
+
id: string
|
|
126
|
+
assurance: ActorAssurance
|
|
127
|
+
isUser: boolean
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const DEFAULT_PATH = process.env.CONARIUM_TOKENS_FILE || 'conarium.tokens.json'
|
|
131
|
+
|
|
132
|
+
/** karma → kişi id. Dosya yoksa null = kişi bazlı kimlik kapalı (hata değil). */
|
|
133
|
+
export function loadTokenStore(path: string = DEFAULT_PATH): Map<string, string> | null {
|
|
134
|
+
if (!existsSync(path)) return null
|
|
135
|
+
const raw = JSON.parse(readFileSync(path, 'utf8')) as { tokens?: { sha256?: string; id?: string }[] }
|
|
136
|
+
const map = new Map<string, string>()
|
|
137
|
+
for (const t of raw.tokens ?? []) {
|
|
138
|
+
if (typeof t.sha256 === 'string' && typeof t.id === 'string' && t.sha256 && t.id) {
|
|
139
|
+
map.set(t.sha256.toLowerCase(), t.id)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return map
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Gelen token'ı kişiye çözer. Eşleşme yoksa ASLA kişi kimliği üretmez —
|
|
147
|
+
* paylaşılan token davranışına düşer.
|
|
148
|
+
*/
|
|
149
|
+
export function resolveActor(
|
|
150
|
+
supplied: string,
|
|
151
|
+
store: Map<string, string> | null,
|
|
152
|
+
fallbackId: string,
|
|
153
|
+
): ResolvedActor {
|
|
154
|
+
if (store && supplied) {
|
|
155
|
+
const h = createHash('sha256').update(supplied).digest('hex')
|
|
156
|
+
const id = store.get(h)
|
|
157
|
+
if (id) return { id, assurance: 'per-user-token', isUser: true }
|
|
158
|
+
}
|
|
159
|
+
return { id: fallbackId, assurance: 'shared-token', isUser: false }
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
- [x] **Step 4: Yeşili doğrula**
|
|
164
|
+
|
|
165
|
+
Çalıştır: `npx vitest run src/tokens.test.ts`
|
|
166
|
+
Beklenen: PASS (5 test)
|
|
167
|
+
|
|
168
|
+
- [x] **Step 5: Tüm takım hâlâ yeşil mi**
|
|
169
|
+
|
|
170
|
+
Çalıştır: `npm test`
|
|
171
|
+
Beklenen: 97 passed (92 mevcut + 5 yeni)
|
|
172
|
+
|
|
173
|
+
- [x] **Step 6: Commit**
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
git add src/tokens.ts src/tokens.test.ts
|
|
177
|
+
git commit -m "feat(identity): kisi basina token deposu
|
|
178
|
+
|
|
179
|
+
Token'lar duz metin degil SHA-256 karmasi olarak saklanir; dosya sizsa bile
|
|
180
|
+
token ele gecmez. Eslesme yoksa ASLA kisi kimligi uretilmez, paylasilan token
|
|
181
|
+
davranisina duser. Dosya yoksa kisi bazli kimlik kapalidir (hata degil)."
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
### Task 2: Denetim kaydında kişi kimliği
|
|
187
|
+
|
|
188
|
+
Canlı etkisi olan parça. Halka açık olarak kabul ettiğimiz açık (*"records the service, not the person"*) burada kapanır.
|
|
189
|
+
|
|
190
|
+
**Files:**
|
|
191
|
+
- Modify: `src/audit.ts` (`AuditEntry` arayüzü ~satır 14, `log()` ~satır 145)
|
|
192
|
+
- Modify: `src/http.ts` (token doğrulama ~satır 82-90)
|
|
193
|
+
- Test: `src/audit.actor.test.ts` (yeni)
|
|
194
|
+
|
|
195
|
+
**Interfaces:**
|
|
196
|
+
- Consumes: Task 1'den `resolveActor`, `loadTokenStore`, `ActorAssurance`.
|
|
197
|
+
- Produces: `AuditEntry` artık isteğe bağlı `actor` girdisi ve `actorAssurance` alanı taşır.
|
|
198
|
+
|
|
199
|
+
- [x] **Step 1: Testi yaz (kırmızı)**
|
|
200
|
+
|
|
201
|
+
`src/audit.actor.test.ts`:
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
import { describe, it, expect } from 'vitest'
|
|
205
|
+
import { Audit } from './audit.js'
|
|
206
|
+
|
|
207
|
+
describe('denetim kaydı aktörü', () => {
|
|
208
|
+
it('aktör verilmezse consumer kullanılır (bugünkü davranış)', () => {
|
|
209
|
+
const a = new Audit({ consumer: 'conarium_c2' })
|
|
210
|
+
const e = a.log({ tool: 'query', denied: false })
|
|
211
|
+
expect(e.actor).toBe('conarium_c2')
|
|
212
|
+
expect(e.actorAssurance).toBe('shared-token')
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
it('aktör verilirse kişi adı yazılır ve güvence beyan edilir', () => {
|
|
216
|
+
const a = new Audit({ consumer: 'conarium_c2' })
|
|
217
|
+
const e = a.log({ tool: 'query', denied: false, actor: 'ayse@sirket.com', actorAssurance: 'per-user-token' })
|
|
218
|
+
expect(e.actor).toBe('ayse@sirket.com')
|
|
219
|
+
expect(e.actorAssurance).toBe('per-user-token')
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
it('aktör alanı hash zincirine dahildir — sonradan değiştirilemez', () => {
|
|
223
|
+
const a1 = new Audit({ consumer: 'c' })
|
|
224
|
+
const h1 = a1.log({ tool: 'query', denied: false, actor: 'ayse@x.com', actorAssurance: 'per-user-token' }).hash
|
|
225
|
+
const a2 = new Audit({ consumer: 'c' })
|
|
226
|
+
const h2 = a2.log({ tool: 'query', denied: false, actor: 'mehmet@x.com', actorAssurance: 'per-user-token' }).hash
|
|
227
|
+
expect(h1).not.toBe(h2)
|
|
228
|
+
})
|
|
229
|
+
})
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Not: `Audit` sınıfı imzalama gerektiriyorsa test başında `process.env.CONARIUM_AUDIT_UNSIGNED = '1'` kur ve sonunda temizle — `src/audit.chain.test.ts` bu deseni kullanıyor, ona bak.
|
|
233
|
+
|
|
234
|
+
- [x] **Step 2: Kırmızıyı doğrula**
|
|
235
|
+
|
|
236
|
+
Çalıştır: `npx vitest run src/audit.actor.test.ts`
|
|
237
|
+
Beklenen: FAIL — `actorAssurance` yok, `log()` `actor` kabul etmiyor
|
|
238
|
+
|
|
239
|
+
- [x] **Step 3: `AuditEntry`'ye alanı ekle**
|
|
240
|
+
|
|
241
|
+
`src/audit.ts`, `AuditEntry` arayüzünde `actor: string` satırının hemen altına:
|
|
242
|
+
|
|
243
|
+
```ts
|
|
244
|
+
/** Kimliğin nasıl kurulduğu. Artefakt kimi değil, NASIL bilindiğini de taşır. */
|
|
245
|
+
actorAssurance?: ActorAssurance
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
Dosyanın import bloğuna ekle:
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
import type { ActorAssurance } from './tokens.js'
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
- [x] **Step 4: `log()` imzasını genişlet**
|
|
255
|
+
|
|
256
|
+
`src/audit.ts`, `log()` metodu — `actor`'ı Omit listesinden çıkar ve isteğe bağlı yap:
|
|
257
|
+
|
|
258
|
+
`actor`'ı Omit listesinde **bırak** (yoksa zorunlu kalır ve `& { actor?: }` ile çelişir, derlenmez), sonra isteğe bağlı olarak geri ekle:
|
|
259
|
+
|
|
260
|
+
```ts
|
|
261
|
+
log(
|
|
262
|
+
entry: Omit<AuditEntry, 'timestamp' | 'actor' | 'prevHash' | 'hash'> & {
|
|
263
|
+
actor?: string
|
|
264
|
+
actorAssurance?: ActorAssurance
|
|
265
|
+
},
|
|
266
|
+
): AuditEntry {
|
|
267
|
+
this.requireSigningCapability()
|
|
268
|
+
|
|
269
|
+
const full: AuditEntry = {
|
|
270
|
+
timestamp: new Date().toISOString(),
|
|
271
|
+
...entry,
|
|
272
|
+
// Aktör verilmediyse eski davranış: örnek başına sabit consumer.
|
|
273
|
+
actor: entry.actor ?? this.consumer,
|
|
274
|
+
actorAssurance: entry.actorAssurance ?? 'shared-token',
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
- [x] **Step 5: Yeşili doğrula**
|
|
279
|
+
|
|
280
|
+
Çalıştır: `npx vitest run src/audit.actor.test.ts`
|
|
281
|
+
Beklenen: PASS (3 test)
|
|
282
|
+
|
|
283
|
+
- [x] **Step 6: HTTP katmanında kimliği çöz**
|
|
284
|
+
|
|
285
|
+
`src/http.ts` — import ekle:
|
|
286
|
+
|
|
287
|
+
```ts
|
|
288
|
+
import { loadTokenStore, resolveActor } from './tokens.js'
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
`TOKEN` sabitinin yanına:
|
|
292
|
+
|
|
293
|
+
```ts
|
|
294
|
+
// Bir kez yüklenir; dosya yoksa null = kişi bazlı kimlik kapalı.
|
|
295
|
+
const TOKEN_STORE = loadTokenStore()
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
`tokenOk(supplied)` kontrolünü genişlet: paylaşılan token VEYA depoda eşleşen bir token kabul edilir.
|
|
299
|
+
|
|
300
|
+
```ts
|
|
301
|
+
const kisi = resolveActor(supplied, TOKEN_STORE, deps.config.consumer)
|
|
302
|
+
if (!kisi.isUser && !tokenOk(supplied)) {
|
|
303
|
+
res.writeHead(401, { 'content-type': 'text/plain' }).end('unauthorized')
|
|
304
|
+
return
|
|
305
|
+
}
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
Consumer değeri `deps.config.consumer` — `src/server.ts:51` `new Audit({ ..., consumer: config.consumer })` ile aynı kaynak. Yeni kavram uydurma.
|
|
309
|
+
|
|
310
|
+
- [x] **Step 7: Kimliği oturum sunucusuna geçir**
|
|
311
|
+
|
|
312
|
+
Mimari kanca hazır: `src/http.ts:127` her oturum için ayrı `Server` kuruyor (`buildServer(deps)`), governance/audit ise ortak. Bir oturum tek token'la açıldığı için **kimlik oturuma sabittir** — global değişken kullanma, eşzamanlı oturumlarda kimlikler karışır.
|
|
313
|
+
|
|
314
|
+
`src/server.ts:73` imzasını genişlet:
|
|
315
|
+
|
|
316
|
+
```ts
|
|
317
|
+
export function buildServer(
|
|
318
|
+
{ config, governance, audit, connectors }: ConariumDeps,
|
|
319
|
+
aktor?: ResolvedActor,
|
|
320
|
+
): Server {
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
Import ekle: `import type { ResolvedActor } from './tokens.js'`
|
|
324
|
+
|
|
325
|
+
`buildServer` gövdesinin en başına tek bir yardımcı koy — `audit.log` çağrıları 8+ yerde, hepsine tek tek alan eklemek DRY değil ve biri unutulur:
|
|
326
|
+
|
|
327
|
+
```ts
|
|
328
|
+
// Oturumun kimliğini her denetim satırına tek yerden geçir.
|
|
329
|
+
// aktor yoksa hiçbir alan eklenmez → log() eski davranışına düşer (consumer).
|
|
330
|
+
const kaydet: typeof audit.log = (e) =>
|
|
331
|
+
audit.log(aktor ? { ...e, actor: aktor.id, actorAssurance: aktor.assurance } : e)
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Sonra bu dosyadaki **tüm** `audit.log(` çağrılarını `kaydet(` ile değiştir (satır 171, 190, 194, 215, 223, 245 ve varsa diğerleri):
|
|
335
|
+
|
|
336
|
+
```bash
|
|
337
|
+
grep -n "audit\.log(" src/server.ts # once say, sonra degistir, sonra tekrar say = 0 olmali
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
`src/http.ts:127`'de oturumun kimliğini geçir:
|
|
341
|
+
|
|
342
|
+
```ts
|
|
343
|
+
const server = buildServer(deps, kisi)
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
`src/index.ts:12` (stdio modu) **değişmez** — aktör verilmez, `service` kalır. Stdio'da kişi kavramı yok.
|
|
347
|
+
|
|
348
|
+
- [x] **Step 8: Tüm takım yeşil**
|
|
349
|
+
|
|
350
|
+
Çalıştır: `npm test`
|
|
351
|
+
Beklenen: 100 passed
|
|
352
|
+
|
|
353
|
+
- [x] **Step 9: Commit**
|
|
354
|
+
|
|
355
|
+
```bash
|
|
356
|
+
git add src/audit.ts src/http.ts src/audit.actor.test.ts
|
|
357
|
+
git commit -m "feat(identity): denetim kaydi kisiyi adiyla yazsin
|
|
358
|
+
|
|
359
|
+
compare.html ve llms.txt'te acikca kabul ettigimiz acik buydu: denetim kaydi
|
|
360
|
+
baglanan SERVISI yaziyordu, kisiyi degil. Kisi basina token eslestiginde artik
|
|
361
|
+
kisi id'si yazilir ve actorAssurance ile kimligin NASIL kuruldugu beyan edilir.
|
|
362
|
+
Token dosyasi yoksa davranis birebir ayni kalir."
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
---
|
|
366
|
+
|
|
367
|
+
### Task 3: Makbuz v0.2 + doğrulayıcı
|
|
368
|
+
|
|
369
|
+
Artefaktın kendisi. **En kritik testi ilk sırada:** eski v0.1 makbuzları hâlâ doğrulanmalı.
|
|
370
|
+
|
|
371
|
+
**Files:**
|
|
372
|
+
- Modify: `src/receipt.ts` (satır 8 sürüm, `ReceiptActor` ~satır 14, `buildReceipt` ~satır 255)
|
|
373
|
+
- Modify: `bin/conarium-verify.mjs` (satır 28 sürüm, `schemaOk` ~satır 267)
|
|
374
|
+
- Test: `src/receipt.actor.test.ts` (yeni)
|
|
375
|
+
|
|
376
|
+
**Interfaces:**
|
|
377
|
+
- Consumes: Task 1'den `ActorAssurance`.
|
|
378
|
+
- Produces: `RECEIPT_VERSION = 'conarium-receipt/0.2'`; `ReceiptActor` artık `assurance` taşır; `ReceiptInput.actor` artık `{ id: string; type?: ActorType; assurance?: ActorAssurance }`.
|
|
379
|
+
|
|
380
|
+
- [x] **Step 1: Testi yaz (kırmızı)**
|
|
381
|
+
|
|
382
|
+
`src/receipt.actor.test.ts`:
|
|
383
|
+
|
|
384
|
+
```ts
|
|
385
|
+
import { describe, it, expect } from 'vitest'
|
|
386
|
+
import { buildReceipt, nextChainState, RECEIPT_VERSION, type ReceiptInput } from './receipt.js'
|
|
387
|
+
|
|
388
|
+
// sampleInput'u src/receipt.leak.test.ts'ten kopyala — orada hazır bir kurucu var.
|
|
389
|
+
|
|
390
|
+
describe('makbuz v0.2 aktörü', () => {
|
|
391
|
+
it('sürüm 0.2', () => {
|
|
392
|
+
expect(RECEIPT_VERSION).toBe('conarium-receipt/0.2')
|
|
393
|
+
})
|
|
394
|
+
|
|
395
|
+
it('aktör türü verilmezse service kalır ve shared-token beyan edilir', () => {
|
|
396
|
+
const r = buildReceipt(sampleInput(), nextChainState(null), null)
|
|
397
|
+
expect(r.actor.type).toBe('service')
|
|
398
|
+
expect(r.actor.assurance).toBe('shared-token')
|
|
399
|
+
})
|
|
400
|
+
|
|
401
|
+
it('kişi token eşleştiyse user + per-user-token yazılır', () => {
|
|
402
|
+
const inp = sampleInput()
|
|
403
|
+
inp.actor = { id: 'ayse@sirket.com', type: 'user', assurance: 'per-user-token' }
|
|
404
|
+
const r = buildReceipt(inp, nextChainState(null), null)
|
|
405
|
+
expect(r.actor).toEqual({ type: 'user', id: 'ayse@sirket.com', assurance: 'per-user-token' })
|
|
406
|
+
})
|
|
407
|
+
|
|
408
|
+
it('user + shared-token kombinasyonu REDDEDILIR — kanıtsız kişi iddiası olamaz', () => {
|
|
409
|
+
const inp = sampleInput()
|
|
410
|
+
inp.actor = { id: 'ayse@sirket.com', type: 'user', assurance: 'shared-token' }
|
|
411
|
+
expect(() => buildReceipt(inp, nextChainState(null), null)).toThrow(/shared-token/)
|
|
412
|
+
})
|
|
413
|
+
})
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
Test imzasız makbuz üretiyorsa `process.env.CONARIUM_AUDIT_UNSIGNED = '1'` kur; `src/receipt.leak.test.ts` bu deseni kullanıyor.
|
|
417
|
+
|
|
418
|
+
- [x] **Step 2: Kırmızıyı doğrula**
|
|
419
|
+
|
|
420
|
+
Çalıştır: `npx vitest run src/receipt.actor.test.ts`
|
|
421
|
+
Beklenen: FAIL — sürüm 0.1, `assurance` yok
|
|
422
|
+
|
|
423
|
+
- [x] **Step 3: Şemayı ve sürümü güncelle**
|
|
424
|
+
|
|
425
|
+
`src/receipt.ts`:
|
|
426
|
+
|
|
427
|
+
```ts
|
|
428
|
+
export const RECEIPT_VERSION = 'conarium-receipt/0.2' as const
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
`ReceiptActor`:
|
|
432
|
+
|
|
433
|
+
```ts
|
|
434
|
+
export interface ReceiptActor {
|
|
435
|
+
type: ActorType
|
|
436
|
+
id: string
|
|
437
|
+
/** Kimliğin nasıl kurulduğu — makbuz kimi değil, NASIL bilindiğini de taşır. */
|
|
438
|
+
assurance: ActorAssurance
|
|
439
|
+
}
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
`ReceiptInput.actor` (satır ~105):
|
|
443
|
+
|
|
444
|
+
```ts
|
|
445
|
+
actor: { id: string; type?: ActorType; assurance?: ActorAssurance }
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
`src/tokens.js`'ten tipi import et:
|
|
449
|
+
|
|
450
|
+
```ts
|
|
451
|
+
import type { ActorAssurance } from './tokens.js'
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
- [x] **Step 4: `buildReceipt`'i güncelle**
|
|
455
|
+
|
|
456
|
+
Satır ~255'teki sabit satırı değiştir:
|
|
457
|
+
|
|
458
|
+
```ts
|
|
459
|
+
actor: buildActor(input.actor),
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
Ve dosyaya yardımcıyı ekle (`buildReceipt`'in hemen üstüne):
|
|
463
|
+
|
|
464
|
+
```ts
|
|
465
|
+
/**
|
|
466
|
+
* Kanıtsız kişi iddiasını YAPISAL olarak imkânsız kılar: 'user' yalnızca
|
|
467
|
+
* doğrulanmış bir güvenceyle yazılabilir. Bu kural yorum değil, kod olmalı —
|
|
468
|
+
* yorum bir sonraki değişiklikte unutulur.
|
|
469
|
+
*/
|
|
470
|
+
function buildActor(a: { id: string; type?: ActorType; assurance?: ActorAssurance }): ReceiptActor {
|
|
471
|
+
const assurance: ActorAssurance = a.assurance ?? 'shared-token'
|
|
472
|
+
const type: ActorType = a.type ?? 'service'
|
|
473
|
+
if (type === 'user' && assurance === 'shared-token') {
|
|
474
|
+
throw new Error(
|
|
475
|
+
'buildReceipt: actor.type "user" cannot be claimed with assurance "shared-token" — ' +
|
|
476
|
+
'a person may only be named when a per-user credential was verified',
|
|
477
|
+
)
|
|
478
|
+
}
|
|
479
|
+
return { type, id: a.id, assurance }
|
|
480
|
+
}
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
Ayrıca satır ~229'daki artık yanlış olan yorumu güncelle: `actor.type is always "service" in v0.1` → v0.2 kuralını anlat.
|
|
484
|
+
|
|
485
|
+
- [x] **Step 5: Yeşili doğrula**
|
|
486
|
+
|
|
487
|
+
Çalıştır: `npx vitest run src/receipt.actor.test.ts`
|
|
488
|
+
Beklenen: PASS (4 test)
|
|
489
|
+
|
|
490
|
+
- [x] **Step 6: Doğrulayıcıyı iki sürüme aç**
|
|
491
|
+
|
|
492
|
+
`bin/conarium-verify.mjs` satır 28:
|
|
493
|
+
|
|
494
|
+
```js
|
|
495
|
+
const RECEIPT_V1 = 'conarium-receipt/0.1'
|
|
496
|
+
const RECEIPT_V2 = 'conarium-receipt/0.2'
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
`RECEIPT_VERSION` kullanan yerleri bu ikisine göre düzelt. `schemaOk` içindeki sürüm ve aktör kontrollerini değiştir:
|
|
500
|
+
|
|
501
|
+
```js
|
|
502
|
+
if (r.v !== RECEIPT_V1 && r.v !== RECEIPT_V2) return `unsupported version ${r.v}`
|
|
503
|
+
...
|
|
504
|
+
// v0.1: aktör "service" olmak zorunda (degismedi — eski makbuzlar aynen dogrulanir)
|
|
505
|
+
if (r.v === RECEIPT_V1) {
|
|
506
|
+
if (!r.actor || r.actor.type !== 'service') return 'actor.type must be "service" in v0.1'
|
|
507
|
+
} else {
|
|
508
|
+
if (!r.actor || (r.actor.type !== 'service' && r.actor.type !== 'user')) {
|
|
509
|
+
return 'actor.type must be "service" or "user" in v0.2'
|
|
510
|
+
}
|
|
511
|
+
if (typeof r.actor.assurance !== 'string' || !r.actor.assurance) {
|
|
512
|
+
return 'actor.assurance is required in v0.2'
|
|
513
|
+
}
|
|
514
|
+
if (r.actor.type === 'user' && r.actor.assurance === 'shared-token') {
|
|
515
|
+
return 'actor.type "user" cannot carry assurance "shared-token"'
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
- [x] **Step 7: Doğrulayıcı regresyonunu koş — EN KRİTİK ADIM**
|
|
521
|
+
|
|
522
|
+
Çalıştır: `npm test`
|
|
523
|
+
Beklenen: mevcut OTS fixture testleri (`test/fixtures/ots/`) **hâlâ geçiyor**. Bunlar v0.1 makbuzları; kırılırsa kendi geçmişimizi bozmuşuz demektir ve devam edilmez.
|
|
524
|
+
|
|
525
|
+
Ayrıca elle:
|
|
526
|
+
|
|
527
|
+
```bash
|
|
528
|
+
node bin/conarium-verify.mjs test/fixtures/ots/receipts.jsonl --pubkey test/fixtures/ots/pubkey.pem; echo "cikis: $?"
|
|
529
|
+
```
|
|
530
|
+
Beklenen: çıkış 0 (fixture adları farklıysa `test/fixtures/ots/` içeriğine bak).
|
|
531
|
+
|
|
532
|
+
- [x] **Step 8: Commit**
|
|
533
|
+
|
|
534
|
+
```bash
|
|
535
|
+
git add src/receipt.ts bin/conarium-verify.mjs src/receipt.actor.test.ts
|
|
536
|
+
git commit -m "feat(receipt): v0.2 — makbuz kisiyi adiyla tasiyabilsin
|
|
537
|
+
|
|
538
|
+
Dogrulayici v0.1'de actor.type'in \"service\" olmasini sart kosuyordu, yani
|
|
539
|
+
\"user\" yazmak uretilen her makbuzu dogrulanamaz yapardi. Bu yuzden surum
|
|
540
|
+
artisi: v0.1 makbuzlari AYNEN dogrulanmaya devam eder (regresyon testiyle
|
|
541
|
+
korunuyor).
|
|
542
|
+
|
|
543
|
+
actor'a assurance eklendi: makbuz kimi degil, kimligin NASIL kuruldugunu da
|
|
544
|
+
tasir. 'user' + 'shared-token' kombinasyonu hem uretimde hem dogrulamada
|
|
545
|
+
reddedilir — kanitsiz kisi iddiasi yapisal olarak imkansiz."
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
---
|
|
549
|
+
|
|
550
|
+
### Task 4: Doğrulayıcı şema testleri + geriye uyum paritesi
|
|
551
|
+
|
|
552
|
+
Spec §8'in doğrulayıcı tarafı ve "hiçbir şey değişmedi" garantisi. Task 3 makbuzu **üretme** tarafında test etti; burası **doğrulama** tarafı. İkisi ayrı kod (`src/receipt.ts` ↔ `bin/conarium-verify.mjs`) ve ayrı kırılırlar.
|
|
553
|
+
|
|
554
|
+
**Files:**
|
|
555
|
+
- Test: `test/verify_actor.test.mjs` (yeni — `test/` altında, mevcut `test/spec_exitcode_drift.mjs` komşusu)
|
|
556
|
+
|
|
557
|
+
**Interfaces:**
|
|
558
|
+
- Consumes: Task 3'ten `RECEIPT_V2` şeması ve `bin/conarium-verify.mjs` çıkış kodları.
|
|
559
|
+
- Produces: yok (yalnız test).
|
|
560
|
+
|
|
561
|
+
- [x] **Step 1: Doğrulayıcı şema testlerini yaz**
|
|
562
|
+
|
|
563
|
+
`test/verify_actor.test.mjs` — doğrulayıcıyı alt süreç olarak koşturup **çıkış kodunu** ölçer (kütüphaneyi değil, gerçek CLI'yi test eder):
|
|
564
|
+
|
|
565
|
+
```js
|
|
566
|
+
import { describe, it, expect } from 'vitest'
|
|
567
|
+
import { execFileSync } from 'node:child_process'
|
|
568
|
+
import { mkdtempSync, writeFileSync } from 'node:fs'
|
|
569
|
+
import { join } from 'node:path'
|
|
570
|
+
import { tmpdir } from 'node:os'
|
|
571
|
+
|
|
572
|
+
/** conarium-verify'i kos, cikis kodunu don. */
|
|
573
|
+
function verify(receipts) {
|
|
574
|
+
const dir = mkdtempSync(join(tmpdir(), 'cnr-ver-'))
|
|
575
|
+
const f = join(dir, 'receipts.jsonl')
|
|
576
|
+
writeFileSync(f, receipts.map(r => JSON.stringify(r)).join('\n') + '\n')
|
|
577
|
+
try {
|
|
578
|
+
execFileSync(process.execPath, ['bin/conarium-verify.mjs', f], { stdio: 'pipe' })
|
|
579
|
+
return 0
|
|
580
|
+
} catch (e) {
|
|
581
|
+
return e.status
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// Task 3'un urettigi gecerli bir v0.2 makbuzunu temel al; alanlari bozarak test et.
|
|
586
|
+
// Temel makbuzu uretmek icin src/receipt.ts'ten buildReceipt kullan (bkz receipt.actor.test.ts).
|
|
587
|
+
|
|
588
|
+
describe('dogrulayici aktor semasi', () => {
|
|
589
|
+
it('v0.2 + user + per-user-token → kabul', () => {
|
|
590
|
+
expect(verify([v2Receipt({ type: 'user', id: 'ayse@x.com', assurance: 'per-user-token' })])).toBe(0)
|
|
591
|
+
})
|
|
592
|
+
|
|
593
|
+
it('v0.2 + user + shared-token → sema hatasi (20)', () => {
|
|
594
|
+
expect(verify([v2Receipt({ type: 'user', id: 'ayse@x.com', assurance: 'shared-token' })])).toBe(20)
|
|
595
|
+
})
|
|
596
|
+
|
|
597
|
+
it('v0.2 + assurance eksik → sema hatasi (20)', () => {
|
|
598
|
+
expect(verify([v2Receipt({ type: 'service', id: 'conarium_c2' })])).toBe(20)
|
|
599
|
+
})
|
|
600
|
+
})
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
`v2Receipt(actor)` yardımcısını dosyanın başında yaz: `buildReceipt` ile geçerli bir makbuz üret, sonra `actor` alanını verilen değerle **değiştir**. Uyarı: imza `chain.hash` üzerinden atıldığı için elle bozulan makbuz imza kontrolünden de düşebilir; bu testler **imzasız** makbuzla koşulmalı (`CONARIUM_AUDIT_UNSIGNED=1`) ki ölçülen şey şema olsun, imza olmasın.
|
|
604
|
+
|
|
605
|
+
- [x] **Step 2: Kırmızıyı doğrula**
|
|
606
|
+
|
|
607
|
+
Çalıştır: `npx vitest run test/verify_actor.test.mjs`
|
|
608
|
+
Beklenen: Task 3 yapılmadıysa hepsi FAIL; yapıldıysa geçer.
|
|
609
|
+
|
|
610
|
+
- [x] **Step 3: Geriye uyum parite testini yaz**
|
|
611
|
+
|
|
612
|
+
Aynı dosyaya ekle — spec §8/8: token dosyası yokken hiçbir şey değişmemeli.
|
|
613
|
+
|
|
614
|
+
```js
|
|
615
|
+
describe('geriye uyum', () => {
|
|
616
|
+
it('token dosyasi YOKKEN uretilen makbuz service + shared-token olur', () => {
|
|
617
|
+
// CONARIUM_TOKENS_FILE'i var olmayan bir yola kur
|
|
618
|
+
process.env.CONARIUM_TOKENS_FILE = join(tmpdir(), 'cnr-yok-' + Date.now() + '.json')
|
|
619
|
+
const r = v2Receipt(undefined) // aktor verilmez
|
|
620
|
+
expect(r.actor.type).toBe('service')
|
|
621
|
+
expect(r.actor.assurance).toBe('shared-token')
|
|
622
|
+
expect(verify([r])).toBe(0)
|
|
623
|
+
})
|
|
624
|
+
})
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
- [x] **Step 4: 401 yolunu test et**
|
|
628
|
+
|
|
629
|
+
Spec §8/6: depo varken bilinmeyen token kimlik üretmemeli **ve** istek reddedilmeli. Bunu `src/tokens.test.ts`'e ek olarak HTTP seviyesinde doğrula — `src/http.ts` içindeki kontrolün gerçekten 401 döndürdüğünü kanıtla. Mevcut HTTP testi yoksa **bu adımı atlama**, `resolveActor` + `tokenOk` bileşiminin 401 verdiğini birim seviyede kanıtla:
|
|
630
|
+
|
|
631
|
+
```js
|
|
632
|
+
it('depo varken bilinmeyen token ne kimlik uretir ne gecer', () => {
|
|
633
|
+
const store = loadTokenStore(tokenFile([{ token: 'tok-ayse', id: 'ayse@x.com' }]))
|
|
634
|
+
const kisi = resolveActor('sahte', store, 'conarium_c2')
|
|
635
|
+
expect(kisi.isUser).toBe(false) // kimlik uretmedi
|
|
636
|
+
// tokenOk('sahte') de false olacagi icin http.ts 401 doner
|
|
637
|
+
})
|
|
638
|
+
```
|
|
639
|
+
|
|
640
|
+
- [x] **Step 5: Tüm takım yeşil**
|
|
641
|
+
|
|
642
|
+
Çalıştır: `npm test`
|
|
643
|
+
Beklenen: hepsi geçiyor, v0.1 fixture'ları dahil.
|
|
644
|
+
|
|
645
|
+
- [x] **Step 6: Commit**
|
|
646
|
+
|
|
647
|
+
```bash
|
|
648
|
+
git add test/verify_actor.test.mjs
|
|
649
|
+
git commit -m "test(verify): dogrulayici aktor semasi + geriye uyum paritesi
|
|
650
|
+
|
|
651
|
+
Uretme tarafi (src/receipt.ts) ile dogrulama tarafi (bin/conarium-verify.mjs)
|
|
652
|
+
ayri kod ve ayri kirilirlar; bu testler CLI'yi alt surec olarak kosturup
|
|
653
|
+
CIKIS KODUNU olcer. Kapsanan: user+shared-token reddi (20), assurance eksikligi
|
|
654
|
+
(20), gecerli v0.2 kabulu (0), ve token dosyasi yokken davranisin birebir ayni
|
|
655
|
+
kalmasi."
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
---
|
|
659
|
+
|
|
660
|
+
## Bitiş kontrolü
|
|
661
|
+
|
|
662
|
+
- [ ] `npm test` tamamen yeşil
|
|
663
|
+
- [ ] `node bin/conarium-verify.mjs` v0.1 fixture'ında çıkış 0
|
|
664
|
+
- [ ] Token dosyası **olmayan** bir kurulumda makbuz `service` + `shared-token` üretiyor
|
|
665
|
+
- [ ] Token dosyası olan kurulumda denetim kaydında kişi adı görünüyor
|
|
666
|
+
|
|
667
|
+
Bunlar geçtikten **sonra** (ayrı iş): `RECEIPT-SPEC.md` boşluk #1, `compare.html` "Per-user identity" satırı, `llms.txt` sınırlaması.
|