spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

sec-default: the collector row's test logs through a built-in's command and reads the entry as the telemetry types give itBrowse files
poteat authored 27 days ago parent 3bcaee1 · commit d825ab00421a
5 changed files+39 -17compared with 3bcaee1
Amods/sec-default/tests/fixtures/export-command.ts
Amods/sec-default/tests/fixtures/exporting.ts
Mmods/sec-default/tests/fixtures/index.ts
Mmods/sec-default/tests/fixtures/withholding.ts
Mmods/sec-default/tests/register.test.ts
@@ -1,0 +1,13 @@
1+import type { CommandRunInput } from 'claude-code'
2+
3+import { FULLSCREEN } from './fullscreen.js'
4+
5+/**
6+ * `/export` as the person types it: the exporting plugin's command.
7+ */
8+export const EXPORT_COMMAND: CommandRunInput = {
9+ command: 'export',
10+ args: '',
11+ origin: { kind: 'composer' },
12+ presentation: FULLSCREEN,
13+}
@@ -1,0 +1,18 @@
1+import type { Plugin } from 'claude-code/testing'
2+
3+/**
4+ * A built-in whose `/export` logs two records for the collector, `kept` and
5+ * `withheld`, and says so.
6+ */
7+export const exporting: Plugin = {
8+ name: 'exporting',
9+ tier: 'builtin',
10+ register(on) {
11+ on('command.run', { command: 'export' }, async $ => {
12+ await $.telemetry.log({ to: 'collector', event: 'kept' })
13+ await $.telemetry.log({ to: 'collector', event: 'withheld' })
14+
15+ return { text: 'exported' }
16+ })
17+ },
18+}
@@ -4,6 +4,8 @@
44 export * from './command-described.js'
55 export * from './denying.js'
66 export * from './dropping.js'
7+export * from './export-command.js'
8+export * from './exporting.js'
79 export * from './fullscreen.js'
810 export * from './listing.js'
911 export * from './managed-policy.js'
@@ -8,9 +8,9 @@
88 name: 'withholding',
99 register(on) {
1010 on('telemetry.log', { to: 'collector' }, ($, e, next) =>
11- e.to === 'collector' && e.event !== 'withheld'
12- ? next({ ...e, attributes: { ...e.attributes, edited: true } })
13- : { deny: 'kept from the collector' },
11+ e.event === 'withheld'
12+ ? { deny: 'kept from the collector' }
13+ : next({ ...e, props: { ...e.props, edited: true } }),
1414 )
1515 },
1616 }
@@ -139,27 +139,16 @@
139139
140140 test(
141141 'a collector record passes over the plugins the person installed',
142- { plugins: [Fixtures.withholding] },
142+ { plugins: [Fixtures.withholding, Fixtures.exporting] },
143143 async ($, on) => {
144144 const reached: unknown[] = []
145145 on('telemetry.log', { to: 'collector' }, ($, e) => {
146- reached.push([e.event, e.to === 'collector' && e.attributes.edited])
146+ reached.push([e.event, e.props?.edited])
147147
148148 return { value: undefined }
149149 })
150150
151- await $.telemetry.log({
152- to: 'collector',
153- event: 'kept',
154- attributes: {},
155- loggedAt: '2026-09-26T10:00:00.000Z',
156- })
157- await $.telemetry.log({
158- to: 'collector',
159- event: 'withheld',
160- attributes: {},
161- loggedAt: '2026-09-26T10:00:01.000Z',
162- })
151+ await $.command.run(Fixtures.EXPORT_COMMAND)
163152
164153 expect(reached).toEqual([
165154 ['kept', undefined],