@things-factory/figure-service 10.1.278 → 10.1.279
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/package.json +23 -8
- package/coverage/clover.xml +0 -6
- package/coverage/coverage-final.json +0 -1
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -101
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov.info +0 -0
- package/dist-server/index.js.map +0 -1
- package/dist-server/migrations/index.js.map +0 -1
- package/dist-server/routers/figure-mesh-router.js.map +0 -1
- package/dist-server/routers/figure-package-router.js.map +0 -1
- package/dist-server/routers/figure-thumbnail-router.js.map +0 -1
- package/dist-server/routes.js.map +0 -1
- package/dist-server/service/figure/event-subscriber.js.map +0 -1
- package/dist-server/service/figure/figure-ai-scenarios-run.js.map +0 -1
- package/dist-server/service/figure/figure-ai-scenarios.js.map +0 -1
- package/dist-server/service/figure/figure-categories.js.map +0 -1
- package/dist-server/service/figure/figure-context.js.map +0 -1
- package/dist-server/service/figure/figure-format.js.map +0 -1
- package/dist-server/service/figure/figure-glb.js.map +0 -1
- package/dist-server/service/figure/figure-history.js.map +0 -1
- package/dist-server/service/figure/figure-llm-provider.js.map +0 -1
- package/dist-server/service/figure/figure-mesh-store.js.map +0 -1
- package/dist-server/service/figure/figure-mutation.js.map +0 -1
- package/dist-server/service/figure/figure-namespace-entity.js.map +0 -1
- package/dist-server/service/figure/figure-namespace-resolver.js.map +0 -1
- package/dist-server/service/figure/figure-namespace.js.map +0 -1
- package/dist-server/service/figure/figure-package-export.js.map +0 -1
- package/dist-server/service/figure/figure-proposal-record.js.map +0 -1
- package/dist-server/service/figure/figure-proposal.js.map +0 -1
- package/dist-server/service/figure/figure-propose-steps.js.map +0 -1
- package/dist-server/service/figure/figure-propose-type.js.map +0 -1
- package/dist-server/service/figure/figure-public.js.map +0 -1
- package/dist-server/service/figure/figure-query.js.map +0 -1
- package/dist-server/service/figure/figure-rename.js.map +0 -1
- package/dist-server/service/figure/figure-replaced-draft.js.map +0 -1
- package/dist-server/service/figure/figure-revert.js.map +0 -1
- package/dist-server/service/figure/figure-subject.js.map +0 -1
- package/dist-server/service/figure/figure-thumbnail-reader.js.map +0 -1
- package/dist-server/service/figure/figure-thumbnail-store.js.map +0 -1
- package/dist-server/service/figure/figure-thumbnail-upgrade.js.map +0 -1
- package/dist-server/service/figure/figure-tools.js.map +0 -1
- package/dist-server/service/figure/figure-type.js.map +0 -1
- package/dist-server/service/figure/figure-write.js.map +0 -1
- package/dist-server/service/figure/figure.js.map +0 -1
- package/dist-server/service/figure/index.js.map +0 -1
- package/dist-server/service/figure-recipe/figure-recipe-resolver.js.map +0 -1
- package/dist-server/service/figure-recipe/figure-recipe-templates.js.map +0 -1
- package/dist-server/service/figure-recipe/figure-recipe-type.js.map +0 -1
- package/dist-server/service/figure-recipe/index.js.map +0 -1
- package/dist-server/service/index.js.map +0 -1
- package/dist-server/tsconfig.tsbuildinfo +0 -1
- package/logs/.08636eb59927f12972f6774f5947c8507b3564c2-audit.json +0 -15
- package/logs/application-2026-09-14-23.log +0 -0
- package/logs/figure-ai-scenarios/2026-11-03T09-31-35-151Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -1167
- package/logs/figure-ai-scenarios/2026-11-03T09-39-05-265Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -904
- package/logs/figure-ai-scenarios/2026-11-03T09-41-49-107Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -1629
- package/logs/figure-ai-scenarios/2026-11-03T09-58-26-681Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -4412
- package/logs/figure-ai-scenarios/2026-11-03T10-16-46-212Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -4513
- package/logs/figure-ai-scenarios/2026-11-03T10-21-07-872Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -4202
- package/logs/figure-ai-scenarios/2026-11-03T10-25-21-721Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -1665
- package/logs/figure-ai-scenarios/2026-11-09T01-28-51-664Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -4484
- package/scripts/build-templates.mts +0 -64
- package/scripts/figure-ai-scenarios-agent.cjs +0 -98
- package/scripts/rename-figures-to-full-names.mjs +0 -211
- package/scripts/templates.test.mts +0 -112
- package/server/index.ts +0 -46
- package/server/migrations/index.ts +0 -9
- package/server/routers/figure-mesh-router.ts +0 -63
- package/server/routers/figure-package-router.ts +0 -53
- package/server/routers/figure-thumbnail-router.ts +0 -159
- package/server/routes.ts +0 -30
- package/server/service/figure/catalog-db.test.ts +0 -162
- package/server/service/figure/event-subscriber.ts +0 -66
- package/server/service/figure/figure-ai-scenarios-run.ts +0 -127
- package/server/service/figure/figure-ai-scenarios.live.test.ts +0 -59
- package/server/service/figure/figure-ai-scenarios.test.ts +0 -109
- package/server/service/figure/figure-ai-scenarios.ts +0 -798
- package/server/service/figure/figure-blueprint-query.test.ts +0 -536
- package/server/service/figure/figure-catalog-seen-db.test.ts +0 -153
- package/server/service/figure/figure-categories.ts +0 -50
- package/server/service/figure/figure-category-db.test.ts +0 -127
- package/server/service/figure/figure-context.test.ts +0 -402
- package/server/service/figure/figure-context.ts +0 -510
- package/server/service/figure/figure-deprecation-db.test.ts +0 -218
- package/server/service/figure/figure-format.test.ts +0 -423
- package/server/service/figure/figure-format.ts +0 -783
- package/server/service/figure/figure-glb.test.ts +0 -112
- package/server/service/figure/figure-glb.ts +0 -251
- package/server/service/figure/figure-history.ts +0 -192
- package/server/service/figure/figure-inspect-db.test.ts +0 -131
- package/server/service/figure/figure-llm-provider.ts +0 -20
- package/server/service/figure/figure-llm-smoke.test.ts +0 -95
- package/server/service/figure/figure-mesh-db.test.ts +0 -246
- package/server/service/figure/figure-mesh-store.ts +0 -91
- package/server/service/figure/figure-mutation.ts +0 -656
- package/server/service/figure/figure-namespace-db.test.ts +0 -315
- package/server/service/figure/figure-namespace-entity.ts +0 -67
- package/server/service/figure/figure-namespace-resolver.ts +0 -54
- package/server/service/figure/figure-namespace.ts +0 -156
- package/server/service/figure/figure-package-export.ts +0 -136
- package/server/service/figure/figure-proposal-db.test.ts +0 -117
- package/server/service/figure/figure-proposal-record.ts +0 -38
- package/server/service/figure/figure-proposal.ts +0 -41
- package/server/service/figure/figure-propose-clips.test.ts +0 -69
- package/server/service/figure/figure-propose-steps.test.ts +0 -324
- package/server/service/figure/figure-propose-steps.ts +0 -354
- package/server/service/figure/figure-propose-type.ts +0 -46
- package/server/service/figure/figure-public-db.test.ts +0 -288
- package/server/service/figure/figure-public.ts +0 -60
- package/server/service/figure/figure-query.ts +0 -511
- package/server/service/figure/figure-release-check.test.ts +0 -63
- package/server/service/figure/figure-release-record-db.test.ts +0 -153
- package/server/service/figure/figure-release-size-db.test.ts +0 -156
- package/server/service/figure/figure-rename-db.test.ts +0 -237
- package/server/service/figure/figure-rename.test.ts +0 -117
- package/server/service/figure/figure-rename.ts +0 -143
- package/server/service/figure/figure-replaced-draft.ts +0 -99
- package/server/service/figure/figure-revert-db.test.ts +0 -163
- package/server/service/figure/figure-revert-race.pg.test.ts +0 -168
- package/server/service/figure/figure-revert.ts +0 -186
- package/server/service/figure/figure-subject.test.ts +0 -41
- package/server/service/figure/figure-subject.ts +0 -21
- package/server/service/figure/figure-thumbnail-db.test.ts +0 -279
- package/server/service/figure/figure-thumbnail-reader.ts +0 -20
- package/server/service/figure/figure-thumbnail-store.ts +0 -111
- package/server/service/figure/figure-thumbnail-upgrade.pg.test.ts +0 -93
- package/server/service/figure/figure-thumbnail-upgrade.ts +0 -70
- package/server/service/figure/figure-tool-doors.test.ts +0 -127
- package/server/service/figure/figure-tools-door-db.test.ts +0 -227
- package/server/service/figure/figure-tools.test.ts +0 -817
- package/server/service/figure/figure-tools.ts +0 -611
- package/server/service/figure/figure-type.ts +0 -241
- package/server/service/figure/figure-write.test.ts +0 -15
- package/server/service/figure/figure-write.ts +0 -131
- package/server/service/figure/figure.ts +0 -241
- package/server/service/figure/index.ts +0 -13
- package/server/service/figure-recipe/figure-recipe-resolver.ts +0 -38
- package/server/service/figure-recipe/figure-recipe-templates.test.ts +0 -47
- package/server/service/figure-recipe/figure-recipe-templates.ts +0 -70
- package/server/service/figure-recipe/figure-recipe-type.ts +0 -31
- package/server/service/figure-recipe/index.ts +0 -3
- package/server/service/index.ts +0 -34
- package/tsconfig.json +0 -14
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { join } from 'path'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Two starts moving the same install's pictures at once, on postgres (chief architect's ruling 2026-10-02, condition 2:
|
|
5
|
-
* the same hash written twice must come to the same result). sqlite holds one connection and cannot show this. Runs
|
|
6
|
-
* only when FIGURE_PG_URL names a server:
|
|
7
|
-
*
|
|
8
|
-
* docker run -d --name fig-revert-pg -e POSTGRES_PASSWORD=figrv -e POSTGRES_USER=figrv -e POSTGRES_DB=figrv \
|
|
9
|
-
* -p 55441:5432 postgres:14-alpine
|
|
10
|
-
* yarn workspace @things-factory/figure-service build:server
|
|
11
|
-
* FIGURE_PG_URL=postgres://figrv:figrv@localhost:55441/figrv \
|
|
12
|
-
* node_modules/.bin/jest --selectProjects figure-service-ts --coverage=false figure-thumbnail-upgrade
|
|
13
|
-
*
|
|
14
|
-
* Every round must end with every picture moved exactly as it was: each row names its own content's hash, no base64
|
|
15
|
-
* is left, and every hash has an attachment holding those bytes. A row emptied without its hash, or a hash with no
|
|
16
|
-
* file, is the defect.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
const url = process.env.FIGURE_PG_URL
|
|
20
|
-
const maybe = url ? describe : describe.skip
|
|
21
|
-
const ROUNDS = 6
|
|
22
|
-
const ROWS = 24
|
|
23
|
-
|
|
24
|
-
maybe('two starts moving pictures at once, on postgres', () => {
|
|
25
|
-
/*
|
|
26
|
-
* attachment-base picks its `contents` column type from `ormconfig.type` when it is loaded; the test process has no
|
|
27
|
-
* ormconfig, which reads as sqlite's blob. This file alone sees postgres, before anything loads attachment-base.
|
|
28
|
-
*/
|
|
29
|
-
jest.doMock('@things-factory/env', () => {
|
|
30
|
-
const real = jest.requireActual('@things-factory/env')
|
|
31
|
-
return { ...real, config: { ...real.config, get: (key: string, fallback?: unknown) => (key === 'ormconfig' ? { type: 'postgres' } : real.config.get(key, fallback)) } }
|
|
32
|
-
})
|
|
33
|
-
const { DataSource } = require('typeorm')
|
|
34
|
-
const { entityClosure } = require(join(__dirname, '..', '..', '..', '..', 'ops-master', 'test', 'support', 'database.cjs'))
|
|
35
|
-
const { NamingStrategy } = require('@things-factory/shell/dist-server/initializers/naming-strategy.js')
|
|
36
|
-
const { Domain } = require('@things-factory/shell')
|
|
37
|
-
const { Attachment } = require('@things-factory/attachment-base')
|
|
38
|
-
const DIST = join(__dirname, '..', '..', '..', 'dist-server', 'service', 'figure')
|
|
39
|
-
const { Figure } = require(join(DIST, 'figure.js'))
|
|
40
|
-
const { FigureHistory } = require(join(DIST, 'figure-history.js'))
|
|
41
|
-
const { FigureReplacedDraft } = require(join(DIST, 'figure-replaced-draft.js'))
|
|
42
|
-
const { moveBase64Thumbnails } = require(join(DIST, 'figure-thumbnail-upgrade.js'))
|
|
43
|
-
const { sha256Of } = require(join(DIST, 'figure-thumbnail-store.js'))
|
|
44
|
-
|
|
45
|
-
const kept = new Map<string, Buffer>()
|
|
46
|
-
let n = 0
|
|
47
|
-
const files = {
|
|
48
|
-
async put(bytes: Buffer, _m: string, name: string) {
|
|
49
|
-
const id = require('crypto').randomUUID()
|
|
50
|
-
const path = `${id}.${name.split('.').pop()}`
|
|
51
|
-
kept.set(path, bytes)
|
|
52
|
-
n++
|
|
53
|
-
return { id, path, size: bytes.length }
|
|
54
|
-
},
|
|
55
|
-
async send() {}
|
|
56
|
-
}
|
|
57
|
-
const open = async (dropSchema: boolean) => {
|
|
58
|
-
const db = new DataSource({ type: 'postgres', url, synchronize: true, dropSchema, entities: entityClosure([Figure, FigureHistory, FigureReplacedDraft, Attachment]), namingStrategy: new NamingStrategy() })
|
|
59
|
-
await db.initialize()
|
|
60
|
-
return db
|
|
61
|
-
}
|
|
62
|
-
let one: any, two: any
|
|
63
|
-
beforeAll(async () => {
|
|
64
|
-
one = await open(true)
|
|
65
|
-
two = await open(false)
|
|
66
|
-
}, 60000)
|
|
67
|
-
afterAll(async () => {
|
|
68
|
-
await one?.destroy()
|
|
69
|
-
await two?.destroy()
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
const picture = (k: number) => `data:image/webp;base64,${Buffer.from([0x52, 0x49, k % 7, k % 5, 9]).toString('base64')}`
|
|
73
|
-
|
|
74
|
-
it('every round: each row moved once, to its own hash, with its bytes kept', async () => {
|
|
75
|
-
for (let round = 0; round < ROUNDS; round++) {
|
|
76
|
-
const domain = await one.getRepository(Domain).save({ name: `pg-${round}`, subdomain: `pg-${round}` })
|
|
77
|
-
const ids: string[] = []
|
|
78
|
-
for (let k = 0; k < ROWS; k++) {
|
|
79
|
-
const r = await one.createQueryBuilder().insert().into(Figure).values({ type: `T${round}_${k}`, name: 'x', source: '{}', state: 'draft', version: 0, thumbnail: picture(k), domain: { id: domain.id } }).callListeners(false).execute()
|
|
80
|
-
ids.push(r.identifiers[0].id)
|
|
81
|
-
}
|
|
82
|
-
await Promise.all([moveBase64Thumbnails(one, files), moveBase64Thumbnails(two, files)])
|
|
83
|
-
for (const [k, id] of ids.entries()) {
|
|
84
|
-
const row = await one.getRepository(Figure).findOneOrFail({ where: { id } })
|
|
85
|
-
const want = sha256Of(Buffer.from(picture(k).split(',')[1], 'base64'))
|
|
86
|
-
expect([row.thumbnail, row.thumbnailHash]).toEqual([null, want])
|
|
87
|
-
const holders = await one.getRepository(Attachment).find({ where: { domain: { id: domain.id }, refType: 'figure-thumbnail', refBy: want } })
|
|
88
|
-
expect(holders.length).toBeGreaterThan(0)
|
|
89
|
-
for (const h of holders) expect(sha256Of(kept.get(h.path)!)).toBe(want)
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}, 120000)
|
|
93
|
-
})
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { IsNull, Not } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
import { Figure } from './figure.js'
|
|
4
|
-
import { FigureHistory } from './figure-history.js'
|
|
5
|
-
import { FigureReplacedDraft } from './figure-replaced-draft.js'
|
|
6
|
-
import { keepThumbnail, thumbnailFiles, type ThumbnailFiles } from './figure-thumbnail-store.js'
|
|
7
|
-
|
|
8
|
-
/*
|
|
9
|
-
* Moves the pictures an install kept as base64 into attachment-base, by their content (ADR-0104 decision 6; chief
|
|
10
|
-
* architect's ruling 2026-10-02, condition 3). Run at start, in the boot's one line (`inBootTurn`).
|
|
11
|
-
*
|
|
12
|
-
* per row the file first -- it cannot be rolled back -- then, in one transaction, the attachment row, the hash,
|
|
13
|
-
* and the base64 emptied. The update only takes a row whose base64 is still the one read, so two starts
|
|
14
|
-
* at once, or a save in between, never empty a picture that was not moved.
|
|
15
|
-
* again safe: a row already moved has no base64 and is not read; a picture already kept is found by its hash.
|
|
16
|
-
* kept a picture that is not a data URL, or a row whose domain cannot be found, keeps its base64 and is
|
|
17
|
-
* counted -- nothing is emptied that was not moved.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
type Moved = { table: string; moved: number; kept: number }
|
|
21
|
-
|
|
22
|
-
const TABLES = [
|
|
23
|
-
{ table: 'figure', entity: Figure },
|
|
24
|
-
{ table: 'figure_history', entity: FigureHistory },
|
|
25
|
-
{ table: 'figure_replaced_draft', entity: FigureReplacedDraft }
|
|
26
|
-
] as const
|
|
27
|
-
|
|
28
|
-
export async function moveBase64Thumbnails(dataSource: any, files: ThumbnailFiles = thumbnailFiles()): Promise<Moved[]> {
|
|
29
|
-
const out: Moved[] = []
|
|
30
|
-
for (const { table, entity } of TABLES) {
|
|
31
|
-
const rows: any[] = await dataSource.getRepository(entity).find({
|
|
32
|
-
where: { thumbnail: Not(IsNull()) },
|
|
33
|
-
relations: { domain: true },
|
|
34
|
-
select: { id: true, thumbnail: true, domain: { id: true }, ...(entity === FigureHistory ? { originalId: true } : {}) },
|
|
35
|
-
withDeleted: true
|
|
36
|
-
})
|
|
37
|
-
let moved = 0,
|
|
38
|
-
kept = 0
|
|
39
|
-
for (const row of rows) {
|
|
40
|
-
/* A release written before releases carried their domain names it through the figure it belongs to. */
|
|
41
|
-
const domainId: string | undefined =
|
|
42
|
-
row.domain?.id ??
|
|
43
|
-
(entity === FigureHistory && row.originalId
|
|
44
|
-
? (await dataSource.getRepository(Figure).findOne({ where: { id: row.originalId }, relations: { domain: true }, select: { id: true, domain: { id: true } }, withDeleted: true }))?.domain?.id
|
|
45
|
-
: undefined)
|
|
46
|
-
if (!domainId) {
|
|
47
|
-
kept++
|
|
48
|
-
continue
|
|
49
|
-
}
|
|
50
|
-
try {
|
|
51
|
-
await dataSource.transaction(async (tx: any) => {
|
|
52
|
-
const hash = await keepThumbnail(tx, { id: domainId }, undefined, row.thumbnail, files)
|
|
53
|
-
await tx
|
|
54
|
-
.createQueryBuilder()
|
|
55
|
-
.update(entity)
|
|
56
|
-
.set({ thumbnailHash: hash, thumbnail: null })
|
|
57
|
-
.where('id = :id AND thumbnail = :was', { id: row.id, was: row.thumbnail })
|
|
58
|
-
.callListeners(false)
|
|
59
|
-
.execute()
|
|
60
|
-
})
|
|
61
|
-
moved++
|
|
62
|
-
} catch (error) {
|
|
63
|
-
console.error(`[figure-service] ${table} ${row.id} 의 썸네일을 옮기지 못했다 — base64 를 그대로 둔다: ${(error as Error)?.message ?? error}`)
|
|
64
|
-
kept++
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
out.push({ table, moved, kept })
|
|
68
|
-
}
|
|
69
|
-
return out
|
|
70
|
-
}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The doors figure's tools pass — ADR-0072 decision 2, ADR-0071 decision 2 addendum (2026-09-18).
|
|
3
|
-
*
|
|
4
|
-
* A declaration nobody reads can be deleted or changed by the next person with no effect. Now it has a
|
|
5
|
-
* reader — the gate decides from this list whether to offer the tool. So this asks two things: did the
|
|
6
|
-
* tool name its doors, and **does each door guard anything.**
|
|
7
|
-
*/
|
|
8
|
-
import { readdirSync, readFileSync } from 'fs'
|
|
9
|
-
import { join } from 'path'
|
|
10
|
-
|
|
11
|
-
import { clearToolRegistry, getAllToolSpecs, getToolRegistryWarnings } from '@things-factory/ai-client-base'
|
|
12
|
-
|
|
13
|
-
import { registerFigureToolCategories } from './figure-tools'
|
|
14
|
-
|
|
15
|
-
describe('figure tools — declared doors', () => {
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
clearToolRegistry()
|
|
18
|
-
registerFigureToolCategories()
|
|
19
|
-
})
|
|
20
|
-
afterAll(() => clearToolRegistry())
|
|
21
|
-
|
|
22
|
-
it('★ every figure tool says which doors it reaches, as a list', () => {
|
|
23
|
-
const undeclared = getAllToolSpecs()
|
|
24
|
-
.filter(spec => !Array.isArray((spec as any).doors))
|
|
25
|
-
.map(spec => spec.name)
|
|
26
|
-
|
|
27
|
-
expect(undeclared).toEqual([])
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('the registry itself finds nothing to report about these specs', () => {
|
|
31
|
-
expect(getToolRegistryWarnings().map(w => `${w.code}:${w.params.tool ?? ''}`)).toEqual([])
|
|
32
|
-
})
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
/*
|
|
36
|
-
* Does each door the tools point at guard anything — the fact the gate stands on.
|
|
37
|
-
*
|
|
38
|
-
* Until 2026-09-18 the tool specs copied a privilege and this spot compared the copy with the door.
|
|
39
|
-
* The copy is gone (ADR-0071 decision 2 addendum) — the gate reads the door's declaration from AUTH's
|
|
40
|
-
* field table directly, so there are no longer two values to compare.
|
|
41
|
-
*
|
|
42
|
-
* What remains is **the fact the gate stands on**: the doors these four tools point at carry a
|
|
43
|
-
* directive. Strip `@privilege` from `Query.figures` and that door opens within the tenant, and the
|
|
44
|
-
* tool opens with it — and nothing else would show it. This catches it.
|
|
45
|
-
*/
|
|
46
|
-
describe('figure tools — the doors they reach are guarded', () => {
|
|
47
|
-
beforeEach(() => {
|
|
48
|
-
clearToolRegistry()
|
|
49
|
-
registerFigureToolCategories()
|
|
50
|
-
})
|
|
51
|
-
afterAll(() => clearToolRegistry())
|
|
52
|
-
|
|
53
|
-
/** 리졸버 원문에서 `Query.figures` 같은 문 이름 → 그 문의 `@privilege` 지시자. */
|
|
54
|
-
const doorPrivileges = (): Map<string, { category: string; privilege: string; owner: boolean }> => {
|
|
55
|
-
const found = new Map<string, { category: string; privilege: string; owner: boolean }>()
|
|
56
|
-
|
|
57
|
-
for (const file of readdirSync(__dirname).filter(one => one.endsWith('.ts') && !one.endsWith('.test.ts'))) {
|
|
58
|
-
const lines = readFileSync(join(__dirname, file), 'utf8').split('\n')
|
|
59
|
-
let privilege: { category: string; privilege: string; owner: boolean } | undefined
|
|
60
|
-
let kind: 'Query' | 'Mutation' | undefined
|
|
61
|
-
let decorator = ''
|
|
62
|
-
|
|
63
|
-
for (const line of lines) {
|
|
64
|
-
const declared = /@privilege\(category: "([^"]+)", privilege: "([^"]+)"(, domainOwnerGranted: (true|false))?\)/.exec(line)
|
|
65
|
-
if (declared) {
|
|
66
|
-
privilege = { category: declared[1]!, privilege: declared[2]!, owner: declared[4] === 'true' }
|
|
67
|
-
continue
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const opens = /@(Query|Mutation)\(/.exec(line)
|
|
71
|
-
if (opens) {
|
|
72
|
-
kind = opens[1] as 'Query' | 'Mutation'
|
|
73
|
-
decorator = line
|
|
74
|
-
continue
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (!kind) {
|
|
78
|
-
/* 지시자와 문 사이에 딴 것이 오면 그 지시자는 이 문의 것이 아니다. */
|
|
79
|
-
if (line.trim() && !line.trim().startsWith('@') && !line.trim().startsWith('*') && !line.trim().startsWith('/*')) {
|
|
80
|
-
privilege = undefined
|
|
81
|
-
}
|
|
82
|
-
continue
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
decorator += '\n' + line
|
|
86
|
-
const method = /^\s*(?:async\s+)?([A-Za-z_$][\w$]*)\s*\(/.exec(line)
|
|
87
|
-
if (!method) continue
|
|
88
|
-
|
|
89
|
-
/*
|
|
90
|
-
필드 이름이 메서드 이름과 다를 수 있는 길은 하나뿐이다 — 데코레이터의 `name:`. 그것이
|
|
91
|
-
나타나면 조용히 메서드 이름으로 읽지 않고 멈춘다. 잘못 읽은 짝은 초록으로 보인다.
|
|
92
|
-
*/
|
|
93
|
-
if (/\bname:\s*'/.test(decorator)) {
|
|
94
|
-
throw new Error(`${file} 의 ${kind} 가 데코레이터에서 이름을 정한다 — 이 시험이 그 길을 아직 안 읽는다`)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (privilege) found.set(`${kind}.${method[1]}`, privilege)
|
|
98
|
-
kind = undefined
|
|
99
|
-
privilege = undefined
|
|
100
|
-
decorator = ''
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return found
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
it('★ every door a tool points at carries the directive that guards it', () => {
|
|
108
|
-
const doors = doorPrivileges()
|
|
109
|
-
|
|
110
|
-
const unguarded = getAllToolSpecs()
|
|
111
|
-
.flatMap(spec =>
|
|
112
|
-
((spec as any).doors ?? []).map((door: string) =>
|
|
113
|
-
doors.has(door) ? undefined : `${spec.name} → ${door}: no such door, or the door declares no privilege`
|
|
114
|
-
)
|
|
115
|
-
)
|
|
116
|
-
.filter(Boolean)
|
|
117
|
-
|
|
118
|
-
expect(unguarded).toEqual([])
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
it('견줄 문을 실제로 찾아 읽었다 — 0 건이면 위 시험은 언제나 초록이다', () => {
|
|
122
|
-
const doors = doorPrivileges()
|
|
123
|
-
expect(doors.get('Query.figures')).toEqual({ category: 'figure', privilege: 'query', owner: true })
|
|
124
|
-
expect(doors.get('Mutation.proposeFigure')).toEqual({ category: 'figure', privilege: 'mutation', owner: true })
|
|
125
|
-
expect(doors.size).toBeGreaterThanOrEqual(4)
|
|
126
|
-
})
|
|
127
|
-
})
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The picture a person attaches in the modeller's dock reaches the step generator, through the conversation's real
|
|
3
|
-
* door (ADR-0061, 2026-10-16 decision 2): `assistantChat` -> `registryAssistantChat` -> `proposeFigureCandidate` ->
|
|
4
|
-
* `proposeFigureSteps`.
|
|
5
|
-
*
|
|
6
|
-
* The audit found the break on this path, not in any one piece: the dock uploads files by `attachmentIds`, the door put
|
|
7
|
-
* them on the model's message only, and the tool looked for `hostContext.image`, which the dock never fills. So this
|
|
8
|
-
* runs the door itself, on sqlite, with the file stored as a conversation's attachment - the provider and the step
|
|
9
|
-
* generator are the only stand-ins.
|
|
10
|
-
*
|
|
11
|
-
* ai-assistant's door is loaded compiled (its type-graphql classes need tsc's metadata), so build it first:
|
|
12
|
-
* yarn workspace @things-factory/ai-assistant build:server
|
|
13
|
-
*/
|
|
14
|
-
import type { DataSource } from 'typeorm'
|
|
15
|
-
|
|
16
|
-
/* Files of a conversation are read through the storage; the database storage keeps them in the row. Set before load. */
|
|
17
|
-
require('@things-factory/env').config.set('storage', { type: 'database' })
|
|
18
|
-
|
|
19
|
-
const { DataSource: TypeOrmDataSource } = require('typeorm')
|
|
20
|
-
const shell = require('@things-factory/shell')
|
|
21
|
-
const authBase = require('@things-factory/auth-base')
|
|
22
|
-
const attachmentBase = require('@things-factory/attachment-base')
|
|
23
|
-
const aiClientBase = require('@things-factory/ai-client-base')
|
|
24
|
-
const aiAssistant = require('@things-factory/ai-assistant')
|
|
25
|
-
|
|
26
|
-
const { __setFigureToolDepsForTest, registerFigureToolCategories } = require('./figure-tools')
|
|
27
|
-
|
|
28
|
-
const PNG = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])
|
|
29
|
-
|
|
30
|
-
let dataSource: DataSource | null = null
|
|
31
|
-
let DOMAIN: any
|
|
32
|
-
let USER: any
|
|
33
|
-
|
|
34
|
-
/** What the step generator was asked - the generator itself is figure-propose-steps' own suite. */
|
|
35
|
-
const proposed: any[] = []
|
|
36
|
-
/** What the conversation's model was handed, each call. */
|
|
37
|
-
const modelCalls: any[][] = []
|
|
38
|
-
|
|
39
|
-
beforeAll(async () => {
|
|
40
|
-
dataSource = new TypeOrmDataSource({
|
|
41
|
-
type: 'sqlite',
|
|
42
|
-
database: ':memory:',
|
|
43
|
-
synchronize: true,
|
|
44
|
-
dropSchema: true,
|
|
45
|
-
namingStrategy: new shell.NamingStrategy(),
|
|
46
|
-
entities: [...shell.entities, ...authBase.entities, ...attachmentBase.entities, ...aiAssistant.entities],
|
|
47
|
-
logging: false
|
|
48
|
-
})
|
|
49
|
-
await dataSource!.initialize()
|
|
50
|
-
/* The door reads through shell's repositories - the same data source. */
|
|
51
|
-
shell.addDataSource('default', dataSource)
|
|
52
|
-
|
|
53
|
-
aiAssistant.registerAssistantMode({
|
|
54
|
-
kind: 'figure.modeller',
|
|
55
|
-
attachments: { kinds: ['image', 'text'] },
|
|
56
|
-
systemPrompt: 'You help a person author a figure.',
|
|
57
|
-
toolCategories: ['figure-authoring']
|
|
58
|
-
})
|
|
59
|
-
/* AUTH's field table is filled when the schema is built; the proposal door is declared open here. */
|
|
60
|
-
process['PRIVILEGE_OF_FIELD']['Mutation.proposeFigure'] = null
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
afterAll(async () => {
|
|
64
|
-
shell.removeDataSource('default')
|
|
65
|
-
await dataSource?.destroy()
|
|
66
|
-
dataSource = null
|
|
67
|
-
aiAssistant.clearAssistantModes()
|
|
68
|
-
aiClientBase.setAIClientForTesting(undefined)
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
beforeEach(async () => {
|
|
72
|
-
await dataSource!.synchronize(true)
|
|
73
|
-
DOMAIN = await dataSource!.getRepository(shell.Domain).save({ name: 'door-probe', subdomain: 'door-probe' })
|
|
74
|
-
USER = await dataSource!.getRepository(authBase.User).save({ name: 'author', email: 'author@door.probe', domains: [DOMAIN] } as any)
|
|
75
|
-
|
|
76
|
-
proposed.length = 0
|
|
77
|
-
modelCalls.length = 0
|
|
78
|
-
aiClientBase.clearToolRegistry()
|
|
79
|
-
__setFigureToolDepsForTest({
|
|
80
|
-
getRepository: () => ({ findOne: async () => null, find: async () => [] }),
|
|
81
|
-
Figure: class {},
|
|
82
|
-
proposeFigureSteps: async (input: any) => {
|
|
83
|
-
proposed.push(input)
|
|
84
|
-
const model = require('@hatiolab/figure-model')
|
|
85
|
-
return { steps: [{ kind: 'rename', name: 'Mixer' }], source: model.createFigureAsset('Mixer'), score: { grade: 'B' }, cost: { triangles: 12 }, attempts: 1 }
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
registerFigureToolCategories()
|
|
89
|
-
|
|
90
|
-
/* The conversation's model asks for a new figure once, then answers. */
|
|
91
|
-
let turn = 0
|
|
92
|
-
aiClientBase.setAIClientForTesting({
|
|
93
|
-
id: 'test:door',
|
|
94
|
-
chat: async () => '',
|
|
95
|
-
generateJSON: async () => ({}),
|
|
96
|
-
listModels: async () => [],
|
|
97
|
-
chatWithTools: async (messages: any[]) => {
|
|
98
|
-
modelCalls.push(messages)
|
|
99
|
-
return turn++ === 0
|
|
100
|
-
? { toolCalls: [{ id: 'p-1', name: 'proposeFigureCandidate', arguments: { prompt: 'make it like the picture', create: true }, type: 'tool_use' }], stopReason: 'tool_use' }
|
|
101
|
-
: { text: 'A candidate is on the card.', toolCalls: [], stopReason: 'end_turn' }
|
|
102
|
-
}
|
|
103
|
-
})
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
/** A conversation about the open figure, and a picture stored with it as the dock's upload stores it. */
|
|
107
|
-
async function conversationWithPicture() {
|
|
108
|
-
const session = await dataSource!.getRepository(aiAssistant.ChatSession).save({
|
|
109
|
-
domain: DOMAIN,
|
|
110
|
-
kind: 'figure.modeller',
|
|
111
|
-
anchorType: 'figure',
|
|
112
|
-
anchorId: 'fig-1',
|
|
113
|
-
visibility: 'open',
|
|
114
|
-
creator: USER,
|
|
115
|
-
updater: USER
|
|
116
|
-
} as any)
|
|
117
|
-
/* As the database storage writes an upload: the path is `<id>.<extension>`, and a read finds the row by that id. */
|
|
118
|
-
const id = require('crypto').randomUUID()
|
|
119
|
-
const picture = await dataSource!.getRepository(attachmentBase.Attachment).save({
|
|
120
|
-
id,
|
|
121
|
-
domain: DOMAIN,
|
|
122
|
-
name: 'front.png',
|
|
123
|
-
mimetype: 'image/png',
|
|
124
|
-
encoding: '7bit',
|
|
125
|
-
category: 'chat',
|
|
126
|
-
refType: 'chat-session',
|
|
127
|
-
refBy: session.id,
|
|
128
|
-
path: `${id}.png`,
|
|
129
|
-
size: String(PNG.length),
|
|
130
|
-
contents: PNG
|
|
131
|
-
} as any)
|
|
132
|
-
return { session, picture }
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const ask = (sessionId: string, attachmentIds: string[], hostContext: any = { figureId: 'fig-1' }) =>
|
|
136
|
-
new aiAssistant.AssistantChatResolver().assistantChat(
|
|
137
|
-
{
|
|
138
|
-
sessionId,
|
|
139
|
-
messages: [{ role: 'user', content: 'make it like this picture' }],
|
|
140
|
-
mode: { kind: 'figure.modeller', target: 'fig-1' },
|
|
141
|
-
hostContext,
|
|
142
|
-
attachmentIds
|
|
143
|
-
},
|
|
144
|
-
{ state: { domain: DOMAIN, user: USER } }
|
|
145
|
-
)
|
|
146
|
-
|
|
147
|
-
describe('a picture sent in the dock', () => {
|
|
148
|
-
it('★ reaches the step generator through the door - the bytes stored with the conversation', async () => {
|
|
149
|
-
const { session, picture } = await conversationWithPicture()
|
|
150
|
-
|
|
151
|
-
const answer = await ask(session.id, [picture.id])
|
|
152
|
-
|
|
153
|
-
expect(answer.proposals).toHaveLength(1)
|
|
154
|
-
expect(proposed).toHaveLength(1)
|
|
155
|
-
expect(proposed[0].images).toHaveLength(1)
|
|
156
|
-
expect(Buffer.from(proposed[0].images[0].data).equals(PNG)).toBe(true)
|
|
157
|
-
expect(proposed[0].images[0].mediaType).toBe('image/png')
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
it('the conversation\'s model reads the same picture on the question', async () => {
|
|
161
|
-
const { session, picture } = await conversationWithPicture()
|
|
162
|
-
|
|
163
|
-
await ask(session.id, [picture.id])
|
|
164
|
-
|
|
165
|
-
const question = modelCalls[0]!.filter((message: any) => message.role === 'user').pop()
|
|
166
|
-
const image = (question.content as any[]).find(part => part.type === 'image')
|
|
167
|
-
expect(Buffer.from(image.source.data).equals(PNG)).toBe(true)
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
it('★ a picture the screen put in the host context does not reach the generator - only what the door checked', async () => {
|
|
171
|
-
const { session } = await conversationWithPicture()
|
|
172
|
-
|
|
173
|
-
await ask(session.id, [], { figureId: 'fig-1', image: { data: PNG.toString('base64'), mediaType: 'image/png' } })
|
|
174
|
-
|
|
175
|
-
expect(proposed).toHaveLength(1)
|
|
176
|
-
expect(proposed[0].images).toBeUndefined()
|
|
177
|
-
})
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
/*
|
|
181
|
-
The next turn's model is told which card an outcome is about (figure audit 2026-10-16 N7). The outcome row names the
|
|
182
|
-
proposal by its key, and the model never saw the key: tool results are not in the history. So the answer that offered
|
|
183
|
-
the card carries, for the model, one line with the key and the card's title.
|
|
184
|
-
*/
|
|
185
|
-
describe('a card the person ran, on the next turn', () => {
|
|
186
|
-
it('★ the model reads the card by its title beside the key the outcome names', async () => {
|
|
187
|
-
const { session } = await conversationWithPicture()
|
|
188
|
-
const first = await ask(session.id, [])
|
|
189
|
-
const card = first.proposals[0]
|
|
190
|
-
await new aiAssistant.ChatSessionResolver().reportProposalOutcome(session.id, card.key, { verdict: 'refused', errorCode: 'REVISION_CONFLICT' }, {
|
|
191
|
-
state: { domain: DOMAIN, user: USER }
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
await ask(session.id, [])
|
|
195
|
-
|
|
196
|
-
const history = modelCalls[2]!
|
|
197
|
-
const offered = history.find((message: any) => message.role === 'assistant' && String(message.content).includes(card.key))
|
|
198
|
-
expect(offered?.content).toContain(`"${card.label}"`)
|
|
199
|
-
const outcome = history.findIndex((message: any) => typeof message.content === 'string' && message.content.includes(`proposal ${card.key}: refused`))
|
|
200
|
-
expect(outcome).toBeGreaterThan(history.indexOf(offered))
|
|
201
|
-
})
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
/*
|
|
205
|
-
A tool that fails is the tool's answer: through the real door, the turn still answers and the model reads why
|
|
206
|
-
(figure audit 2026-10-16 N1). Before, `assistantChat` rejected and the dock showed the kernel's English reasons.
|
|
207
|
-
*/
|
|
208
|
-
describe('a proposal that could not be made', () => {
|
|
209
|
-
it('★ the turn answers, and the model is handed the reasons', async () => {
|
|
210
|
-
__setFigureToolDepsForTest({
|
|
211
|
-
getRepository: () => ({ findOne: async () => null, find: async () => [] }),
|
|
212
|
-
Figure: class {},
|
|
213
|
-
proposeFigureSteps: async () => {
|
|
214
|
-
throw Object.assign(new Error('The figure could not be made.'), { reasons: ['ATTACH_FACE: steps[4] faces along x'] })
|
|
215
|
-
}
|
|
216
|
-
})
|
|
217
|
-
const { session } = await conversationWithPicture()
|
|
218
|
-
|
|
219
|
-
const answer = await ask(session.id, [])
|
|
220
|
-
|
|
221
|
-
expect(answer.proposals ?? []).toHaveLength(0)
|
|
222
|
-
const results = modelCalls[1]!.at(-1)!.content.filter((part: any) => part.type === 'tool_result')
|
|
223
|
-
expect(results).toHaveLength(1)
|
|
224
|
-
expect(results[0].isError).toBe(true)
|
|
225
|
-
expect(JSON.parse(results[0].content).message).toMatch(/could not be made\.\nATTACH_FACE: steps\[4\]/)
|
|
226
|
-
})
|
|
227
|
-
})
|