feat(telemetry): require explicit opt-in

This commit is contained in:
Turtle
2026-08-10 17:45:50 +08:00
parent 504e96a049
commit e6eb44ed2a
53 changed files with 265 additions and 370 deletions
+6 -7
View File
@@ -7,9 +7,9 @@
*/
import {
ConsentResolver,
TelemetryReporter,
buildTelemetryPayload,
resolveTelemetryConsent,
type ConsentDecision,
} from '@deepseek-ai/dsh-telemetry'
@@ -17,7 +17,7 @@ import {
export interface CommandTelemetryEvent {
/** The dsh-sdk command that ran. */
command: string
/** Project directory whose consent, `cordis.yml`, and `package.json` are read. */
/** Project directory whose `cordis.yml` and `package.json` may be reported. */
cwd: string
/** Wall-clock duration in milliseconds. */
durationMs: number
@@ -27,12 +27,12 @@ export interface CommandTelemetryEvent {
/** Injectable consent and delivery hooks for tests. */
export interface CommandTelemetryDeps {
resolve?: (cwd: string) => Promise<ConsentDecision>
resolve?: () => ConsentDecision | Promise<ConsentDecision>
reporter?: Pick<TelemetryReporter, 'report' | 'flush'>
}
/**
* Resolve consent for the project and, when allowed, assemble and send one
* Resolve the shared telemetry mode and, when allowed, assemble and send one
* telemetry event, draining in-flight sends before returning. Swallows every
* error so telemetry can never change a command's result.
* @param event - the command lifecycle facts.
@@ -43,9 +43,8 @@ export async function reportCommandTelemetry(
deps: CommandTelemetryDeps = {},
): Promise<void> {
try {
/* v8 ignore next -- the production ConsentResolver is exercised by the built-bin smoke */
const resolve = deps.resolve ?? (cwd => new ConsentResolver().resolve(cwd))
const consent = await resolve(event.cwd)
/* v8 ignore next -- the production resolver is exercised by its owning tests */
const consent = await (deps.resolve?.() ?? resolveTelemetryConsent())
if (!consent.allowed) return
const payload = await buildTelemetryPayload({
command: event.command,
@@ -611,12 +611,12 @@ describe('command telemetry', () => {
const reporter = { report: () => { sent.push(1) }, flush: async () => {} }
await reportCommandTelemetry(
{ command: 'build', cwd: dir, durationMs: 5, success: true },
{ resolve: async () => ({ allowed: true, reason: 'absent' }), reporter },
{ resolve: async () => ({ allowed: true, reason: 'FULL' }), reporter },
)
expect(sent).toHaveLength(1)
await reportCommandTelemetry(
{ command: 'build', cwd: dir, durationMs: 5, success: true },
{ resolve: async () => ({ allowed: false, reason: 'disabled' }), reporter },
{ resolve: async () => ({ allowed: false, reason: 'DISABLED' }), reporter },
)
expect(sent).toHaveLength(1)
await expect(reportCommandTelemetry(
+2 -2
View File
@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write packages/scaffold/telemetry/README.md
README.md: 024ff8724604426d3d77609929ca40341f98e0fb
README.zh.md: 8d69d9289ed9c412e4d38fe9b24bb3222f81f94a
README.md: 670937d70dd2cabc0c77306a6239caa23123ae6f
README.zh.md: 6bbd17a46fe9828b3722c5703c1484eafebb8540
+3 -3
View File
@@ -2,17 +2,17 @@
English | [中文](README.zh.md)
Launcher-side telemetry primitives for the dsh-sdk toolchain. This is a plain library the launcher imports around each command; it is **not** a Cordis plugin, because `build` and first-init `create` never boot Cordis. Wiring the reporter into the launcher command dispatch and adding the telemetry consent feature to the `dsh-helper` catalog live in their owning packages, not here.
Launcher-side telemetry primitives for the dsh-sdk toolchain. This is a plain library the launcher imports around each command; it is not a Cordis plugin because `build` and first-init `create` never boot Cordis. Wiring the reporter into launcher command dispatch lives in its owning package.
| Export | Role |
|---|---|
| `SecretRedactor` | Conservative safety backstop: replaces secret-shaped values (secret-like keys, known token shapes, PEM blocks, URL credentials, high-entropy opaque tokens) with a placeholder in both parsed values (`redactValue`) and raw text (`redactText`). Never drops a field or line. |
| `ConsentResolver` | Parses (never boots) a project `cordis.yml` and reads the telemetry entry's enabled/disabled state as consent; `DO_NOT_TRACK`/CI env force a hard opt-out. |
| `resolveTelemetryConsent` | Reads the shared `DSH_TELEMETRY_MODE`; only `FULL` permits launcher reporting, while `FEEDBACK_ONLY`, `DISABLED`, unset, and empty values deny it. |
| `buildTelemetryPayload` | Assembles `{command, durationMs, success, cordisYmlContent, packageJsonContent}`, running the redactor over the full `cordis.yml` and `package.json` text. Never reads `.env`; `package.json` ships only alongside a `cordis.yml`, so a command run in a non-SDK directory never uploads that directory's unrelated manifest. |
| `getOrCreateAnonymousId` | Random UUID persisted in the harness home resolved by [`@deepseek-ai/dsh-paths`](../../util/paths/README.md) (`$DSH_HOME` > `~/.dsh`), scoped to that home rather than the machine, never derived from git. |
| `TelemetryReporter` | Fire-and-forget send: `report()` never blocks or throws; delivery resolves on every path; `flush()` optionally drains in-flight sends within a cap. |
Consent is carried by the telemetry entry in `cordis.yml`, so disabling telemetry is disabling that entry. Telemetry reports by default and is off only when a present telemetry entry is explicitly `disabled`: a missing `cordis.yml` (first `create`), an enabled entry, or a `cordis.yml` with no telemetry entry all report. `DO_NOT_TRACK`/CI always deny. The no-config and absent-entry defaults are configurable on `ConsentResolver`.
`DSH_TELEMETRY_MODE` is the single positive consent setting for session and launcher telemetry. `FULL` enables this launcher feed; `FEEDBACK_ONLY` keeps command telemetry off and permits only feedback-triggered Session Log sharing; every other supported state keeps this feed off.
The collection endpoint is a fixed constant (`DSH_TELEMETRY_ENDPOINT`).
+3 -3
View File
@@ -2,17 +2,17 @@
[English](README.md) | 中文
用于 dsh-sdk 工具链的启动器侧 telemetry 原语。这是启动器在执行每个命令时导入的普通库;它**不是** Cordis 插件,因为 `build` 与首次初始化的 `create` 从不启动 Cordis。将 reporter 接入启动器命令分发,并把 telemetry consent 功能加入 `dsh-helper` 目录,属于各自所属包的职责,而不是此包的职责。
用于 dsh-sdk 工具链的启动器侧 telemetry 原语。这是启动器在执行每个命令时导入的普通库;它不是 Cordis 插件,因为 `build` 与首次初始化的 `create` 从不启动 Cordis。将 reporter 接入启动器命令分发属于其所在包的职责。
| 导出 | 职责 |
|---|---|
| `SecretRedactor` | 保守的安全后备:在已解析值(`redactValue`)与原始文本(`redactText`)中,将形似密钥的值(疑似密钥的键名、已知 token 格式、PEM 块、URL 凭据、高熵不透明 token)替换为占位符。绝不删除字段或行。 |
| `ConsentResolver` | 解析项目 `cordis.yml`(绝不启动),读取 telemetry 配置项的启用/禁用状态作为 consent;`DO_NOT_TRACK`CI 环境会强制完全停止上报。 |
| `resolveTelemetryConsent` | 读取共享的 `DSH_TELEMETRY_MODE`;只有 `FULL` 允许启动器上报,`FEEDBACK_ONLY``DISABLED`、未设置和空值都会拒绝。 |
| `buildTelemetryPayload` | 组装 `{command, durationMs, success, cordisYmlContent, packageJsonContent}`,对完整的 `cordis.yml``package.json` 文本运行 redactor。绝不读取 `.env`;发送 `package.json` 的前提是同时存在 `cordis.yml`,因此在非 SDK 目录运行的命令不会上传该目录中无关的 manifest(元数据清单)。 |
| `getOrCreateAnonymousId` | 将随机 UUID 持久化到 [`@deepseek-ai/dsh-paths`](../../util/paths/README.md) 解析出的 harness home`$DSH_HOME` > `~/.dsh`);其范围限定为该 home,而不是整台机器,且绝不从 git 派生。 |
| `TelemetryReporter` | 即发即弃发送:`report()` 绝不阻塞或抛出;无论经过哪条路径,发送操作最终都会结束;`flush()` 可以在上限内排空进行中的发送。 |
Consent 由 `cordis.yml` 中的 telemetry 配置项承载,因此禁用 telemetry 就是禁用该配置项。telemetry 默认上报,只有已经存在的 telemetry 配置项被显式设为 `disabled` 时才关闭:缺少 `cordis.yml`(首次 `create`)、配置项已启用,或 `cordis.yml` 中没有 telemetry 配置项时都会上报。`DO_NOT_TRACK`/CI 始终拒绝。无配置与缺少配置项的默认值可以通过 `ConsentResolver` 配置
`DSH_TELEMETRY_MODE` 是会话与启动器 telemetry 的唯一正向授权配置。`FULL` 启用该启动器数据流;`FEEDBACK_ONLY` 保持命令 telemetry 关闭,只允许由反馈触发的 Session Log 共享;其他受支持的状态都会保持该数据流关闭
收集端点是固定常量(`DSH_TELEMETRY_ENDPOINT`)。
-3
View File
@@ -24,9 +24,6 @@
"lib/types/**/*.d.ts"
],
"license": "BSD-3-Clause",
"dependencies": {
"yaml": "^2.9.0"
},
"peerDependencies": {
"@deepseek-ai/dsh-brand": "^0.0.1",
"@deepseek-ai/dsh-invariants": "^0.0.1",
@@ -1,42 +1,18 @@
/**
* Consent resolution for dsh-sdk telemetry.
* Consent resolution for dsh-sdk launcher telemetry.
*
* Telemetry is OFF only when `cordis.yml` contains a telemetry entry that is
* explicitly `disabled`; every other file state reports (no `cordis.yml`, an
* enabled entry, or no telemetry entry at all). The resolver PARSES `cordis.yml`
* — it never boots a Cordis application — because several launcher commands
* (`build`, `create`) never boot Cordis at all. `DO_NOT_TRACK` and CI
* environment signals force a denial regardless of file state.
* `DSH_TELEMETRY_MODE` is the shared consent setting for session and launcher
* telemetry. Only `FULL` permits launcher reporting; unset and empty values
* resolve to `DISABLED`.
*
* @module @deepseek-ai/dsh-telemetry/consent-resolver
*/
import { readFile } from 'node:fs/promises'
import { join } from 'node:path'
import { parseDocument, type ScalarTag } from 'yaml'
/** Default `cordis.yml` entry name that carries telemetry consent. */
export const DEFAULT_TELEMETRY_PLUGIN_NAME = '@deepseek-ai/dsh-telemetry'
/**
* Passthrough for Cordis' `!!js` expression tag so parsing consent never fails
* on projects that inline JavaScript expressions; the resolver only reads plain
* `name`/`disabled` scalars and does not evaluate expressions.
*/
const JS_EXPRESSION_TAG: ScalarTag = {
tag: 'tag:yaml.org,2002:js',
resolve: value => value,
}
/** Why telemetry is or is not permitted for one command. */
export type ConsentReason =
| 'enabled'
| 'disabled'
| 'absent'
| 'no-config'
| 'do-not-track'
| 'ci'
| 'unreadable'
| 'FULL'
| 'FEEDBACK_ONLY'
| 'DISABLED'
/** Resolved telemetry consent for one command invocation. */
export interface ConsentDecision {
@@ -46,80 +22,21 @@ export interface ConsentDecision {
reason: ConsentReason
}
/** Tuning for {@link ConsentResolver}; every field defaults to a documented value. */
export interface ConsentResolverOptions {
/** `cordis.yml` entry name whose enabled state carries consent. */
telemetryPluginName?: string
/** Environment used for `DO_NOT_TRACK`/CI checks; defaults to `process.env`. */
env?: NodeJS.ProcessEnv
/** Honor `DO_NOT_TRACK`/CI env signals as a hard opt-out. Defaults to `true`. */
honorEnvOptOut?: boolean
/** Consent when `cordis.yml` does not exist yet (first `create`). Defaults to `true` (telemetry is default-on). */
allowWhenNoConfig?: boolean
/** Consent when `cordis.yml` exists but has no telemetry entry. Defaults to `true` (report unless a present entry is disabled). */
allowWhenEntryAbsent?: boolean
}
/** Whether an environment variable is set to a non-empty, non-"0"/"false" value. */
function envEnabled(value: string | undefined): boolean {
if (value === undefined) return false
const normalized = value.trim().toLowerCase()
return normalized.length > 0 && normalized !== '0' && normalized !== 'false'
}
/** Read a `cordis.yml` entry's `name`/`disabled` scalars, tolerating `!!js` tags. */
function readTelemetryEntry(text: string, pluginName: string): { present: boolean; disabled: boolean } {
const document = parseDocument(text, { customTags: [JS_EXPRESSION_TAG] })
const contents: unknown = document.toJS({ maxAliasCount: -1 })
if (!Array.isArray(contents)) return { present: false, disabled: false }
for (const entry of contents) {
if (entry === null || typeof entry !== 'object') continue
const record = entry as Record<string, unknown>
if (record.name === pluginName) return { present: true, disabled: record.disabled === true }
}
return { present: false, disabled: false }
}
/** Resolve telemetry consent by parsing a project's `cordis.yml` and the environment. */
export class ConsentResolver {
readonly #pluginName: string
readonly #env: NodeJS.ProcessEnv
readonly #honorEnvOptOut: boolean
readonly #allowWhenNoConfig: boolean
readonly #allowWhenEntryAbsent: boolean
/** @param options - plugin name, environment, and default-decision knobs. */
constructor(options: ConsentResolverOptions = {}) {
this.#pluginName = options.telemetryPluginName ?? DEFAULT_TELEMETRY_PLUGIN_NAME
this.#env = options.env ?? process.env
this.#honorEnvOptOut = options.honorEnvOptOut ?? true
this.#allowWhenNoConfig = options.allowWhenNoConfig ?? true
this.#allowWhenEntryAbsent = options.allowWhenEntryAbsent ?? true
}
/**
* Resolve consent for a command run in the given project directory.
* @param projectDir - absolute or relative project root containing `cordis.yml`.
* @returns the consent decision and the signal that produced it.
*/
async resolve(projectDir: string): Promise<ConsentDecision> {
if (this.#honorEnvOptOut) {
if (envEnabled(this.#env.DO_NOT_TRACK)) return { allowed: false, reason: 'do-not-track' }
if (envEnabled(this.#env.CI)) return { allowed: false, reason: 'ci' }
}
let text: string
try {
text = await readFile(join(projectDir, 'cordis.yml'), 'utf8')
} catch (error) {
// Missing cordis.yml is the first-init (`create`) path; any other read
// fault is treated conservatively as its own reason.
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
return { allowed: this.#allowWhenNoConfig, reason: 'no-config' }
}
return { allowed: false, reason: 'unreadable' }
}
const entry = readTelemetryEntry(text, this.#pluginName)
if (!entry.present) return { allowed: this.#allowWhenEntryAbsent, reason: 'absent' }
return entry.disabled ? { allowed: false, reason: 'disabled' } : { allowed: true, reason: 'enabled' }
/**
* Resolve launcher telemetry consent from the shared telemetry mode.
* @param env - Environment containing `DSH_TELEMETRY_MODE`; defaults to `process.env`.
* @returns Whether launcher telemetry may report and the resolved mode.
*/
export function resolveTelemetryConsent(env: NodeJS.ProcessEnv = process.env): ConsentDecision {
const mode = env.DSH_TELEMETRY_MODE || 'DISABLED'
switch (mode) {
case 'FULL':
return { allowed: true, reason: 'FULL' }
case 'FEEDBACK_ONLY':
return { allowed: false, reason: 'FEEDBACK_ONLY' }
case 'DISABLED':
return { allowed: false, reason: 'DISABLED' }
default:
throw new Error(`unsupported DSH_TELEMETRY_MODE ${JSON.stringify(mode)}`)
}
}
+4 -7
View File
@@ -2,10 +2,9 @@
* Launcher-side telemetry for the dsh-sdk toolchain: secret redaction, consent
* resolution, anonymous id, payload assembly, and a fire-and-forget reporter.
*
* This package is a plain library the launcher imports around each command it
* is NOT a Cordis plugin (several commands never boot Cordis). Wiring it into
* the launcher command dispatch and the helper feature catalog lives outside
* this package.
* This package is a plain library the launcher imports around each command; it
* is not a Cordis plugin because several commands never boot Cordis. Wiring
* reporting into launcher command dispatch lives outside this package.
*
* FIXME: rename to `@deepseek-ai/dsh-sdk-telemetry` before the first tagged release —
* the current name collides with the `dsh-session-telemetry` family; this is
@@ -24,13 +23,11 @@ export {
} from './secret-redactor.ts'
export type { SecretRedactorOptions } from './secret-redactor.ts'
export {
ConsentResolver,
DEFAULT_TELEMETRY_PLUGIN_NAME,
resolveTelemetryConsent,
} from './consent-resolver.ts'
export type {
ConsentDecision,
ConsentReason,
ConsentResolverOptions,
} from './consent-resolver.ts'
export {
ANONYMOUS_ID_FILE_NAME,
@@ -1,132 +1,41 @@
import { mkdtemp, mkdir, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, describe, expect, it } from 'vitest'
import { ConsentResolver, DEFAULT_TELEMETRY_PLUGIN_NAME, type ConsentDecision } from '@deepseek-ai/dsh-telemetry'
import { describe, expect, it } from 'vitest'
import {
resolveTelemetryConsent,
type ConsentDecision,
} from '@deepseek-ai/dsh-telemetry'
const dirs: string[] = []
async function projectDir(cordisYml?: string): Promise<string> {
const dir = await mkdtemp(join(tmpdir(), 'dsh-consent-'))
dirs.push(dir)
if (cordisYml !== undefined) await writeFile(join(dir, 'cordis.yml'), cordisYml, 'utf8')
return dir
}
afterEach(async () => {
await Promise.all(dirs.splice(0).map(dir => import('node:fs/promises').then(fs => fs.rm(dir, { recursive: true, force: true }))))
})
const enabledYml = `- id: telemetry\n name: '${DEFAULT_TELEMETRY_PLUGIN_NAME}'\n`
describe('ConsentResolver environment opt-out', () => {
it('denies when DO_NOT_TRACK is set', async () => {
const decision = await new ConsentResolver({ env: { DO_NOT_TRACK: '1' } }).resolve(await projectDir(enabledYml))
expect(decision).toEqual<ConsentDecision>({ allowed: false, reason: 'do-not-track' })
describe('resolveTelemetryConsent', () => {
it('denies launcher telemetry when the shared mode is unset or empty', () => {
expect(resolveTelemetryConsent({})).toEqual<ConsentDecision>({ allowed: false, reason: 'DISABLED' })
expect(resolveTelemetryConsent({ DSH_TELEMETRY_MODE: '' }))
.toEqual<ConsentDecision>({ allowed: false, reason: 'DISABLED' })
})
it('denies when CI is set', async () => {
const decision = await new ConsentResolver({ env: { CI: 'true' } }).resolve(await projectDir(enabledYml))
expect(decision).toEqual<ConsentDecision>({ allowed: false, reason: 'ci' })
it('denies launcher telemetry in DISABLED and FEEDBACK_ONLY modes', () => {
expect(resolveTelemetryConsent({ DSH_TELEMETRY_MODE: 'DISABLED' }))
.toEqual<ConsentDecision>({ allowed: false, reason: 'DISABLED' })
expect(resolveTelemetryConsent({ DSH_TELEMETRY_MODE: 'FEEDBACK_ONLY' }))
.toEqual<ConsentDecision>({ allowed: false, reason: 'FEEDBACK_ONLY' })
})
it('ignores falsy env values and continues to the file', async () => {
const decision = await new ConsentResolver({ env: { DO_NOT_TRACK: '0', CI: 'false' } })
.resolve(await projectDir(enabledYml))
expect(decision).toEqual<ConsentDecision>({ allowed: true, reason: 'enabled' })
it('allows launcher telemetry only in FULL mode', () => {
expect(resolveTelemetryConsent({ DSH_TELEMETRY_MODE: 'FULL' }))
.toEqual<ConsentDecision>({ allowed: true, reason: 'FULL' })
})
it('can be told to ignore env opt-out signals', async () => {
const decision = await new ConsentResolver({ env: { DO_NOT_TRACK: '1' }, honorEnvOptOut: false })
.resolve(await projectDir(enabledYml))
expect(decision).toEqual<ConsentDecision>({ allowed: true, reason: 'enabled' })
it('rejects an unsupported non-empty mode', () => {
expect(() => resolveTelemetryConsent({ DSH_TELEMETRY_MODE: 'full' }))
.toThrow('unsupported DSH_TELEMETRY_MODE "full"')
})
it('reads process.env by default', async () => {
const saved = { CI: process.env.CI, DO_NOT_TRACK: process.env.DO_NOT_TRACK }
delete process.env.CI
delete process.env.DO_NOT_TRACK
it('reads process.env by default', () => {
const saved = process.env.DSH_TELEMETRY_MODE
process.env.DSH_TELEMETRY_MODE = 'FULL'
try {
const decision = await new ConsentResolver().resolve(await projectDir(enabledYml))
expect(decision).toEqual<ConsentDecision>({ allowed: true, reason: 'enabled' })
expect(resolveTelemetryConsent()).toEqual<ConsentDecision>({ allowed: true, reason: 'FULL' })
} finally {
if (saved.CI !== undefined) process.env.CI = saved.CI
if (saved.DO_NOT_TRACK !== undefined) process.env.DO_NOT_TRACK = saved.DO_NOT_TRACK
if (saved === undefined) delete process.env.DSH_TELEMETRY_MODE
else process.env.DSH_TELEMETRY_MODE = saved
}
})
})
describe('ConsentResolver cordis.yml state', () => {
const resolver = new ConsentResolver({ env: {} })
it('allows when the telemetry entry is enabled', async () => {
expect(await resolver.resolve(await projectDir(enabledYml)))
.toEqual<ConsentDecision>({ allowed: true, reason: 'enabled' })
})
it('denies when the telemetry entry is disabled', async () => {
const yml = `- id: telemetry\n name: '${DEFAULT_TELEMETRY_PLUGIN_NAME}'\n disabled: true\n`
expect(await resolver.resolve(await projectDir(yml)))
.toEqual<ConsentDecision>({ allowed: false, reason: 'disabled' })
})
it('tolerates !!js expression tags while reading plain scalars', async () => {
const yml = [
'- id: telemetry',
` name: '${DEFAULT_TELEMETRY_PLUGIN_NAME}'`,
'- id: llm',
' name: \'@deepseek-ai/dsh-llm-deepseek\'',
' config:',
' apiKeyEnv: DEEPSEEK_API_KEY',
' model: !!js process.env.DEEPSEEK_MODEL',
'',
].join('\n')
expect(await resolver.resolve(await projectDir(yml)))
.toEqual<ConsentDecision>({ allowed: true, reason: 'enabled' })
})
it('reports (allows) when cordis.yml has no telemetry entry', async () => {
const yml = '- id: llm\n name: \'@deepseek-ai/dsh-llm-deepseek\'\n'
expect(await resolver.resolve(await projectDir(yml)))
.toEqual<ConsentDecision>({ allowed: true, reason: 'absent' })
})
it('can be told to deny when the entry is absent', async () => {
const yml = '- id: llm\n name: \'@deepseek-ai/dsh-llm-deepseek\'\n'
const decision = await new ConsentResolver({ env: {}, allowWhenEntryAbsent: false }).resolve(await projectDir(yml))
expect(decision).toEqual<ConsentDecision>({ allowed: false, reason: 'absent' })
})
it('skips non-object sequence items and a non-sequence root, still reporting absent', async () => {
expect(await resolver.resolve(await projectDir('- just-a-string\n- id: x\n name: y\n')))
.toEqual<ConsentDecision>({ allowed: true, reason: 'absent' })
expect(await resolver.resolve(await projectDir('root: not-a-sequence\n')))
.toEqual<ConsentDecision>({ allowed: true, reason: 'absent' })
})
it('honors a custom telemetry plugin name', async () => {
const yml = '- id: t\n name: \'my-consent-marker\'\n'
const decision = await new ConsentResolver({ env: {}, telemetryPluginName: 'my-consent-marker' })
.resolve(await projectDir(yml))
expect(decision).toEqual<ConsentDecision>({ allowed: true, reason: 'enabled' })
})
})
describe('ConsentResolver missing or unreadable cordis.yml', () => {
it('reports no-config and allows by default on first init', async () => {
expect(await new ConsentResolver({ env: {} }).resolve(await projectDir()))
.toEqual<ConsentDecision>({ allowed: true, reason: 'no-config' })
})
it('can deny on first init', async () => {
const decision = await new ConsentResolver({ env: {}, allowWhenNoConfig: false }).resolve(await projectDir())
expect(decision).toEqual<ConsentDecision>({ allowed: false, reason: 'no-config' })
})
it('denies with an unreadable reason when cordis.yml is not a regular file', async () => {
const dir = await projectDir()
await mkdir(join(dir, 'cordis.yml')) // a directory where the resolver expects a file
expect(await new ConsentResolver({ env: {} }).resolve(dir))
.toEqual<ConsentDecision>({ allowed: false, reason: 'unreadable' })
})
})
@@ -9,8 +9,8 @@ import {
type TelemetryPayload,
} from '@deepseek-ai/dsh-telemetry'
const ALLOW: ConsentDecision = { allowed: true, reason: 'enabled' }
const DENY: ConsentDecision = { allowed: false, reason: 'disabled' }
const ALLOW: ConsentDecision = { allowed: true, reason: 'FULL' }
const DENY: ConsentDecision = { allowed: false, reason: 'DISABLED' }
const anon = (value = 'anon-123'): (() => Promise<AnonymousId>) => async () => value as AnonymousId
function okResponse(): Response {