merge origin/main into docs font branch

This commit is contained in:
Andrey Avtomonov 2026-05-21 01:29:49 +02:00
commit c64f1088d6
10 changed files with 360 additions and 60 deletions

View file

@ -1,5 +1,5 @@
{
"title": "Concepts",
"defaultOpen": true,
"pages": ["the-context-layer", "semantic-layer-internals", "context-as-code"]
"pages": ["the-context-layer", "semantic-layer-internals", "wiki-retrieval", "context-as-code"]
}

View file

@ -195,6 +195,10 @@ wiki pages are written and prunes `sl_refs` during ingest when their target
sources are deleted or their measures are renamed - so a stale page can never
quietly route an agent to a definition that no longer exists.
For how the hybrid search pipeline ranks pages, how `[[wikilinks]]` extend
the graph, and how ingest authors pages from evidence, read
[Wiki retrieval](/docs/concepts/wiki-retrieval).
The split between the two pillars is sharp:
| Put it in YAML | Put it in Markdown |

View file

@ -0,0 +1,280 @@
---
title: Wiki retrieval
description: How ktx ranks wiki pages with hybrid search, links them into a graph, and keeps both sides anchored to evidence.
---
The wiki is the prose half of the context layer. Agents reach it two ways:
they search for a page, then follow references inside the pages they
already opened. This page covers how both work.
- The wiki page contract that retrieval and validation depend on.
- The hybrid search pipeline that turns a question into ranked pages.
- The reference graph agents traverse without rerunning search.
- How pages get authored from evidence, and how broken edges get pruned.
## The wiki page contract
A wiki page is a Markdown file with a YAML frontmatter block. Frontmatter
carries metadata; the prose below it is free-form. Keys are flat tokens
(`revenue`, `mart_account_segments`), not paths, so every page is
addressable as `[[key]]` from any other page.
```markdown
# wiki/global/revenue.md
---
summary: Paid order value after refunds
tags: [finance, orders]
sl_refs: [warehouse.orders]
refs: [segment-classification]
usage_mode: auto
---
Revenue is paid order amount after refund adjustments.
Use `orders.total_revenue` for recognized order value and
`orders.order_count` for paid order volume.
```
| Field | Purpose |
|-------|---------|
| `summary` | One-line description shown in search results and the agent's knowledge index |
| `tags` | Topic labels mixed into the search text and used for filtering |
| `refs` | Outgoing edges to other wiki pages by key |
| `sl_refs` | Outgoing edges to semantic-layer sources by `connection.source` name |
| `usage_mode` | `always`, `auto`, or `never` - whether the agent must, may, or must not surface this page |
| `source` | Where the page came from when authored by ingest (e.g. `historic-sql`, `dbt`) |
| `usage` | Stats attached to historic-SQL pattern pages: executions, distinct users, runtime percentiles, error rate |
Pages live under two scopes. `wiki/global/*.md` is the team's shared
context; `wiki/user/<user>/*.md` is per-agent scratch space that shadows
global pages with the same key.
## What retrieval does
A wiki search runs the same ordered steps every time.
1. **Normalize the query.** Lowercase, tokenize, deduplicate terms.
2. **Score in three lanes.** Lexical (SQLite FTS5 bm25), semantic
(cosine similarity over embeddings), and token (term-overlap fallback)
each rank every page independently.
3. **Fuse with Reciprocal Rank Fusion.** Each lane contributes
`weight / (60 + rank)` to a candidate's score. Lanes that fail or
skip are dropped, not zeroed.
4. **Order and trim.** Sort by fused score, then by how many lanes
matched, then by id for stable tie-breaks. Return the top `limit`
results with their summaries.
5. **Hydrate on demand.** The agent calls `wiki_read` to load full
bodies for the few pages that look relevant.
<figure
className="not-prose my-10 overflow-hidden rounded-lg border border-fd-border bg-fd-card shadow-sm"
aria-label="Three retrieval lanes fused with Reciprocal Rank Fusion"
>
<div className="border-b border-fd-border bg-fd-muted/35 px-5 py-4">
<p className="text-[11px] font-semibold uppercase tracking-[0.08em] text-fd-primary">
{"Hybrid retrieval"}
</p>
<h3
className="mt-1 text-base font-semibold tracking-normal text-fd-foreground sm:text-lg"
style={{ fontFamily: "var(--font-display)" }}
>
{"Three lanes, one ranking"}
</h3>
</div>
<div className="p-6">
<div className="grid gap-3 md:grid-cols-3">
<div className="rounded-md border border-fd-border bg-fd-background p-4">
<p className="text-sm font-semibold text-fd-foreground">{"lexical"}</p>
<p className="mt-1 font-mono text-[11px] text-fd-muted-foreground">{"sqlite fts5 / bm25"}</p>
<p className="mt-3 text-xs leading-5 text-fd-muted-foreground">
{"Matches stems and phrases. Strong on the exact terms the team already uses."}
</p>
<p className="mt-3 text-[11px] uppercase tracking-[0.08em] text-fd-muted-foreground">
<span className="text-fd-foreground">{"weight "}</span>{"1.5"}
</p>
</div>
<div className="rounded-md border border-fd-border bg-fd-background p-4">
<p className="text-sm font-semibold text-fd-foreground">{"semantic"}</p>
<p className="mt-1 font-mono text-[11px] text-fd-muted-foreground">{"cosine over embeddings"}</p>
<p className="mt-3 text-xs leading-5 text-fd-muted-foreground">
{"Catches synonyms and paraphrases the lexical lane misses."}
</p>
<p className="mt-3 text-[11px] uppercase tracking-[0.08em] text-fd-muted-foreground">
<span className="text-fd-foreground">{"weight "}</span>{"2"}
</p>
</div>
<div className="rounded-md border border-fd-border bg-fd-background p-4">
<p className="text-sm font-semibold text-fd-foreground">{"token"}</p>
<p className="mt-1 font-mono text-[11px] text-fd-muted-foreground">{"term-overlap fallback"}</p>
<p className="mt-3 text-xs leading-5 text-fd-muted-foreground">
{"Always available, so short queries still produce candidates."}
</p>
<p className="mt-3 text-[11px] uppercase tracking-[0.08em] text-fd-muted-foreground">
<span className="text-fd-foreground">{"weight "}</span>{"0.75"}
</p>
</div>
</div>
<div className="mt-5 rounded-md border border-fd-primary/40 bg-fd-background p-4">
<p className="text-[11px] font-semibold uppercase tracking-[0.08em] text-fd-primary">
{"Reciprocal Rank Fusion"}
</p>
<p className="mt-1 font-mono text-[12px] text-fd-foreground">
{"score = Σ weight / (60 + rank)"}
</p>
<p className="mt-2 text-xs leading-5 text-fd-muted-foreground">
{"Pages that rank well in multiple lanes outscore pages that rank well in only one."}
</p>
</div>
</div>
<figcaption className="border-t border-fd-border bg-fd-muted/25 px-5 py-3 text-[11.5px] leading-5 text-fd-muted-foreground">
<span className="font-medium text-fd-foreground">{"Defaults are tunable. "}</span>
{"Lane weights and the RRF constant K are configuration, not assumptions."}
</figcaption>
</figure>
The text each lane scores is built deterministically: page key, summary,
body, and tags concatenated in that order. A precise summary and the
right tags make a page reachable before its body matches anything.
## The page graph
Two frontmatter fields and one inline syntax turn the wiki into a graph
the agent traverses without re-running search.
| Edge | Source | Target |
|------|--------|--------|
| `sl_refs: [warehouse.orders]` | Frontmatter | Semantic source by name |
| `refs: [segment-classification]` | Frontmatter | Another wiki page by key |
| `[[segment-classification]]` | Inline in body | Another wiki page by key |
`refs` stays in the prose layer; `sl_refs` crosses into the executable
half of the context layer. Inline `[[wikilinks]]` are extracted from
page bodies at validation time and treated as declared `refs`.
<figure
className="not-prose my-10 overflow-hidden rounded-lg border border-fd-border bg-fd-card shadow-sm"
aria-label="Example wiki cross-reference graph"
>
<div className="border-b border-fd-border bg-fd-muted/35 px-5 py-4">
<p className="text-[11px] font-semibold uppercase tracking-[0.08em] text-fd-primary">
{"Anatomy of a traversal"}
</p>
<h3
className="mt-1 text-base font-semibold tracking-normal text-fd-foreground sm:text-lg"
style={{ fontFamily: "var(--font-display)" }}
>
{"Edges to prose, edges to SQL"}
</h3>
</div>
<div className="p-6">
<div className="grid gap-3 md:grid-cols-[1fr_1fr]">
<div className="rounded-md border-2 bg-fd-background p-4" style={{ borderColor: "#10b981" }}>
<p className="font-mono text-[11px] font-semibold" style={{ color: "#10b981" }}>
{"wiki/global/revenue.md"}
</p>
<p className="mt-2 text-sm font-semibold text-fd-foreground">{"revenue"}</p>
<p className="mt-3 text-[11px] uppercase tracking-[0.08em] text-fd-muted-foreground">
{"declares"}
</p>
<ul className="mt-1 space-y-1 text-xs text-fd-muted-foreground">
<li><span className="font-mono text-fd-foreground">{"sl_refs"}</span>: warehouse.orders</li>
<li><span className="font-mono text-fd-foreground">{"refs"}</span>: segment-classification</li>
</ul>
</div>
<div className="rounded-md border bg-fd-background p-4" style={{ borderColor: "#10b981", borderStyle: "dashed" }}>
<p className="font-mono text-[11px] font-semibold" style={{ color: "#10b981" }}>
{"wiki/global/segment-classification.md"}
</p>
<p className="mt-2 text-sm font-semibold text-fd-foreground">{"segment-classification"}</p>
<p className="mt-3 text-[11px] uppercase tracking-[0.08em] text-fd-muted-foreground">
{"declares"}
</p>
<ul className="mt-1 space-y-1 text-xs text-fd-muted-foreground">
<li><span className="font-mono text-fd-foreground">{"sl_refs"}</span>: warehouse.customers</li>
</ul>
</div>
</div>
<div className="my-4 grid gap-2 text-center text-xs font-medium text-fd-muted-foreground md:grid-cols-[1fr_1fr]">
<div>{"revenue → warehouse.orders · sl_refs"}</div>
<div>{"revenue → segment-classification · refs"}</div>
</div>
<div className="grid gap-3 md:grid-cols-[1fr_1fr]">
<div className="rounded-md border-2 bg-fd-background p-4" style={{ borderColor: "#3b82f6" }}>
<p className="font-mono text-[11px] font-semibold" style={{ color: "#3b82f6" }}>
{"semantic-layer/warehouse/orders.yaml"}
</p>
<p className="mt-2 text-sm font-semibold text-fd-foreground">{"warehouse.orders"}</p>
<p className="mt-1 text-xs text-fd-muted-foreground">{"grain: order_id · measure: total_revenue"}</p>
</div>
<div className="rounded-md border-2 bg-fd-background p-4" style={{ borderColor: "#3b82f6" }}>
<p className="font-mono text-[11px] font-semibold" style={{ color: "#3b82f6" }}>
{"semantic-layer/warehouse/customers.yaml"}
</p>
<p className="mt-2 text-sm font-semibold text-fd-foreground">{"warehouse.customers"}</p>
<p className="mt-1 text-xs text-fd-muted-foreground">{"grain: customer_id · dim: segment"}</p>
</div>
</div>
</div>
<figcaption className="border-t border-fd-border bg-fd-muted/25 px-5 py-3 text-[11.5px] leading-5 text-fd-muted-foreground">
{"Green nodes are wiki pages; blue nodes are semantic sources."}
</figcaption>
</figure>
## Keeping the graph live
A page that references a deleted source is worse than no reference at
all - it sends the agent confidently to a definition that no longer
exists. **ktx** prevents that with three layered checks:
- **At write time.** Every `refs` entry and `[[wikilink]]` is validated
against the pages visible in the current scope. A write that targets
a missing page is rejected before any file changes.
- **At ingest time.** Adapters prune `sl_refs` when the target source
is deleted, mark stale pattern pages with `stale_since`, and set
`archived_since` on retired pages instead of removing them silently.
- **At session end.** Every page touched by an ingest run is re-scanned
for references that resolved at write time but no longer point at
a live target. Dangling pairs are reported so the next iteration can
fix them.
## Where the pages come from
**ktx** writes wiki pages from evidence, not free invention. Each input
contributes a different kind of page, and accepted edits feed the next
ingest as input.
| Evidence | What it produces |
|----------|------------------|
| Schema scans | One page per material table, with grain, columns, and known constraints |
| Query history | Pattern pages with `usage` frontmatter for executions, distinct users, runtime percentiles, and error rate |
| dbt manifests | Pages per model, exposure, and test, with `sl_refs` to the matching semantic source |
| MetricFlow, Looker, Metabase | Pages per metric, explore, or saved question, linked back to the source artifact |
| Notion, docs, analyst notes | Pages preserving business definitions, policies, and incident write-ups |
| Agent and analyst edits | First-class input to the next ingest, not a fork |
Provenance stays with the page. Ingested pages keep HTML comments like
`<!-- from: raw-sources/.../cards/69.json -->` inline, so a reviewer can
walk from the prose back to the artifact that produced it.
## Agent usage notes
Point an agent at this page when it needs to explain why a wiki search
returned the pages it did, why a write was rejected, or how the wiki
stays in step with the semantic layer.
| Agent task | Relevant section | Next page |
|------------|------------------|-----------|
| Explain why two searches return different pages for the same query | What retrieval does | [ktx wiki](/docs/cli-reference/ktx-wiki) |
| Decide whether to add a `refs` or `sl_refs` entry | The page graph | [Writing Context](/docs/guides/writing-context) |
| Repair a wiki write rejected for missing references | Keeping the graph live | [Writing Context](/docs/guides/writing-context) |
| Describe how historic SQL becomes a wiki page | Where the pages come from | [Building Context](/docs/guides/building-context) |
| Explain raw-source provenance comments | Where the pages come from | [Context as Code](/docs/concepts/context-as-code) |

View file

@ -1,10 +1,12 @@
import { createRequire } from 'node:module';
import type { ReindexSummary } from '@ktx/context/index-sync';
import { describe, expect, it, vi } from 'vitest';
import { renderReindexJson, renderReindexPlain, reindexHasErrors } from './admin-reindex.js';
import { runKtxCli } from './index.js';
const CLI_VERSION = (createRequire(import.meta.url)('@ktx/cli/package.json') as { version: string }).version;
const cliVersion = (createRequire(import.meta.url)('@ktx/cli/package.json') as { version: string })
.version;
function makeIo(options: { stdoutIsTTY?: boolean } = {}) {
let stdout = '';
@ -140,7 +142,7 @@ describe('admin reindex Commander routing', () => {
force: true,
json: true,
output: 'plain',
cliVersion: CLI_VERSION,
cliVersion,
},
io.io,
);

View file

@ -18,7 +18,9 @@ import {
} from './index.js';
const require = createRequire(import.meta.url);
const CLI_VERSION = (require('@ktx/cli/package.json') as { version: string }).version;
const cliPackageJson = require('@ktx/cli/package.json') as { name: string; version: string };
const cliVersion = cliPackageJson.version;
function makeIo(options: { stdoutIsTty?: boolean } = {}) {
let stdout = '';
@ -46,7 +48,7 @@ describe('getKtxCliPackageInfo', () => {
it('identifies the CLI package and its context dependency', () => {
expect(getKtxCliPackageInfo()).toEqual({
name: '@ktx/cli',
version: CLI_VERSION,
version: cliVersion,
contextPackageName: '@ktx/context',
});
});
@ -56,8 +58,9 @@ describe('getKtxCliPackageInfo', () => {
expect(packageJson).toMatchObject({
name: '@ktx/cli',
version: CLI_VERSION,
version: cliVersion,
});
expect(cliVersion).toMatch(/^\d+\.\d+\.\d+/);
});
it('normalizes public package metadata from package.json contents', () => {
@ -115,7 +118,7 @@ describe('runKtxCli', () => {
await expect(runKtxCli(['--version'], testIo.io)).resolves.toBe(0);
expect(testIo.stdout()).toBe(`@ktx/cli ${CLI_VERSION}\n`);
expect(testIo.stdout()).toBe(`@ktx/cli ${cliVersion}\n`);
expect(testIo.stderr()).toBe('');
});
@ -305,7 +308,7 @@ describe('runKtxCli', () => {
1,
{
command: 'install',
cliVersion: CLI_VERSION,
cliVersion,
feature: 'local-embeddings',
force: true,
},
@ -315,7 +318,7 @@ describe('runKtxCli', () => {
2,
{
command: 'start',
cliVersion: CLI_VERSION,
cliVersion,
projectDir: expect.any(String),
feature: 'local-embeddings',
force: true,
@ -326,7 +329,7 @@ describe('runKtxCli', () => {
3,
{
command: 'stop',
cliVersion: CLI_VERSION,
cliVersion,
projectDir: expect.any(String),
all: false,
},
@ -336,7 +339,7 @@ describe('runKtxCli', () => {
4,
{
command: 'stop',
cliVersion: CLI_VERSION,
cliVersion,
projectDir: expect.any(String),
all: true,
},
@ -346,7 +349,7 @@ describe('runKtxCli', () => {
5,
{
command: 'status',
cliVersion: CLI_VERSION,
cliVersion,
json: true,
},
statusIo.io,
@ -419,7 +422,7 @@ describe('runKtxCli', () => {
expect.objectContaining({
command: 'query',
projectDir: tempDir,
cliVersion: CLI_VERSION,
cliVersion,
runtimeInstallPolicy: 'prompt',
query: expect.objectContaining({ measures: ['orders.order_count'], dimensions: [] }),
}),
@ -434,7 +437,7 @@ describe('runKtxCli', () => {
).resolves.toBe(0);
expect(sl).toHaveBeenLastCalledWith(
expect.objectContaining({
cliVersion: CLI_VERSION,
cliVersion,
runtimeInstallPolicy: 'auto',
}),
autoIo.io,
@ -450,7 +453,7 @@ describe('runKtxCli', () => {
).resolves.toBe(0);
expect(sl).toHaveBeenLastCalledWith(
expect.objectContaining({
cliVersion: CLI_VERSION,
cliVersion,
runtimeInstallPolicy: 'never',
}),
noInputIo.io,
@ -586,7 +589,7 @@ describe('runKtxCli', () => {
skipAgents: false,
inputMode: 'auto',
yes: false,
cliVersion: CLI_VERSION,
cliVersion,
skipLlm: false,
skipEmbeddings: false,
databaseSchemas: [],
@ -716,7 +719,7 @@ describe('runKtxCli', () => {
inputMode: 'disabled',
depth: 'fast',
queryHistory: 'default',
cliVersion: CLI_VERSION,
cliVersion,
runtimeInstallPolicy: 'never',
},
testIo.io,
@ -743,7 +746,7 @@ describe('runKtxCli', () => {
inputMode: 'auto',
depth: 'deep',
queryHistory: 'default',
cliVersion: CLI_VERSION,
cliVersion,
runtimeInstallPolicy: 'prompt',
},
testIo.io,
@ -820,7 +823,7 @@ describe('runKtxCli', () => {
json: false,
inputMode: 'disabled',
queryHistory: 'default',
cliVersion: CLI_VERSION,
cliVersion,
runtimeInstallPolicy: 'never',
},
testIo.io,
@ -1125,7 +1128,7 @@ describe('runKtxCli', () => {
command: 'run',
projectDir: tempDir,
inputMode: 'disabled',
cliVersion: CLI_VERSION,
cliVersion,
anthropicApiKeyEnv: 'ANTHROPIC_API_KEY', // pragma: allowlist secret
llmModel: 'claude-sonnet-4-6',
skipLlm: false,
@ -1164,7 +1167,7 @@ describe('runKtxCli', () => {
command: 'run',
projectDir: tempDir,
inputMode: 'disabled',
cliVersion: CLI_VERSION,
cliVersion,
llmBackend: 'vertex',
vertexProject: 'local-gcp-project',
vertexLocation: 'us-east5',
@ -1201,7 +1204,7 @@ describe('runKtxCli', () => {
command: 'run',
projectDir: tempDir,
inputMode: 'disabled',
cliVersion: CLI_VERSION,
cliVersion,
llmBackend: 'claude-code',
llmModel: 'opus',
skipLlm: false,
@ -1309,7 +1312,7 @@ describe('runKtxCli', () => {
projectDir: '/tmp/project',
inputMode: 'disabled',
yes: true,
cliVersion: CLI_VERSION,
cliVersion,
skipLlm: true,
skipEmbeddings: true,
databaseDrivers: ['postgres'],
@ -1650,7 +1653,7 @@ describe('runKtxCli', () => {
queryFile: '/tmp/query.json',
execute: false,
format: 'json',
cliVersion: CLI_VERSION,
cliVersion,
runtimeInstallPolicy: 'auto',
},
autoIo.io,
@ -1664,7 +1667,7 @@ describe('runKtxCli', () => {
queryFile: '/tmp/query.json',
execute: false,
format: 'json',
cliVersion: CLI_VERSION,
cliVersion,
runtimeInstallPolicy: 'never',
},
neverIo.io,

View file

@ -141,10 +141,13 @@ async function writeWorkspaceFixture(root) {
describe('publicNpmPackageLayout', () => {
it('uses the public npm release version for the tarball name', () => {
const layout = publicNpmPackageLayout('/repo/ktx');
const expectedTarballName = `kaelio-ktx-${PUBLIC_NPM_PACKAGE_VERSION}.tgz`;
assert.equal(publicNpmPackageTarballName(), expectedTarballName);
assert.equal(layout.tarballPath, `/repo/ktx/dist/artifacts/npm/${expectedTarballName}`);
assert.match(PUBLIC_NPM_PACKAGE_VERSION, /^\d+\.\d+\.\d+/);
assert.equal(publicNpmPackageTarballName(), `kaelio-ktx-${PUBLIC_NPM_PACKAGE_VERSION}.tgz`);
assert.equal(
layout.tarballPath,
`/repo/ktx/dist/artifacts/npm/kaelio-ktx-${PUBLIC_NPM_PACKAGE_VERSION}.tgz`,
);
});
});
@ -268,7 +271,6 @@ describe('createPublicNpmPackageTree', () => {
describe('publicNpmPackCommand', () => {
it('packs the assembled public package with pnpm', () => {
const layout = publicNpmPackageLayout('/repo/ktx');
const expectedTarballName = `kaelio-ktx-${PUBLIC_NPM_PACKAGE_VERSION}.tgz`;
assert.deepEqual(publicNpmPackCommand(layout), {
command: 'pnpm',
@ -276,7 +278,7 @@ describe('publicNpmPackCommand', () => {
'--config.node-linker=hoisted',
'pack',
'--out',
`/repo/ktx/dist/artifacts/npm/${expectedTarballName}`,
`/repo/ktx/dist/artifacts/npm/kaelio-ktx-${PUBLIC_NPM_PACKAGE_VERSION}.tgz`,
],
cwd: '/repo/ktx/dist/public-npm-package',
});

View file

@ -52,7 +52,7 @@ describe('runtimeWheelPyproject', () => {
const pyproject = runtimeWheelPyproject();
assert.match(pyproject, /name = "kaelio-ktx"/);
assert.match(pyproject, new RegExp(`version = "${RUNTIME_WHEEL_PACKAGE_VERSION.replaceAll('.', '\\.')}"`));
assert.match(pyproject, new RegExp(`version = "${RUNTIME_WHEEL_PACKAGE_VERSION.replace(/\./g, '\\.')}"`));
assert.match(pyproject, /ktx-daemon = "ktx_daemon\.__main__:main"/);
assert.match(pyproject, /packages = \["semantic_layer", "ktx_daemon"\]/);
assert.match(pyproject, /\[project\.optional-dependencies\]/);
@ -110,6 +110,6 @@ describe('runtimeWheelBuildCommand', () => {
cwd: '/repo/ktx',
});
assert.equal(RUNTIME_WHEEL_DISTRIBUTION_NAME, 'kaelio-ktx');
assert.match(RUNTIME_WHEEL_PACKAGE_VERSION, /^\d+\.\d+\.\d+(?:rc\d+)?$/);
assert.match(RUNTIME_WHEEL_PACKAGE_VERSION, /^\d+\.\d+\.\d+/);
});
});

View file

@ -2,6 +2,7 @@ import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { describe, it } from 'node:test';
import { PUBLIC_NPM_PACKAGE_VERSION } from './build-public-npm-package.mjs';
import {
buildLocalEmbeddingsSmokeEnv,
expectedPublicKtxVersionPattern,
@ -11,10 +12,8 @@ import {
publicKtxTarballName,
validateEmbeddingResponse,
} from './local-embeddings-runtime-smoke.mjs';
import {
PUBLIC_NPM_PACKAGE_NAME,
PUBLIC_NPM_PACKAGE_VERSION,
} from './build-public-npm-package.mjs';
const PUBLIC_TARBALL_NAME = `kaelio-ktx-${PUBLIC_NPM_PACKAGE_VERSION}.tgz`;
const OTHER_PUBLIC_TARBALL_NAME = 'kaelio-ktx-9.9.9.tgz';
describe('localEmbeddingsSmokeOptIn', () => {
it('skips unless the smoke is explicitly enabled', () => {
@ -39,10 +38,7 @@ describe('localEmbeddingsSmokeOptIn', () => {
describe('publicKtxTarballName', () => {
it('selects the public @kaelio/ktx tarball name', () => {
assert.equal(
publicKtxTarballName(['kaelio-ktx-0.1.0-rc.1.tgz', 'ignore-me.tgz']),
'kaelio-ktx-0.1.0-rc.1.tgz',
);
assert.equal(publicKtxTarballName([PUBLIC_TARBALL_NAME, 'ignore-me.tgz']), PUBLIC_TARBALL_NAME);
});
it('fails when the public package tarball is missing', () => {
@ -54,7 +50,7 @@ describe('publicKtxTarballName', () => {
it('fails when multiple public package tarballs are present', () => {
assert.throws(
() => publicKtxTarballName(['kaelio-ktx-0.1.0-rc.1.tgz', 'kaelio-ktx-0.2.0.tgz']),
() => publicKtxTarballName([PUBLIC_TARBALL_NAME, OTHER_PUBLIC_TARBALL_NAME]),
/Expected exactly one @kaelio\/ktx tarball/,
);
});
@ -64,7 +60,7 @@ describe('expectedPublicKtxVersionPattern', () => {
it('matches the public package version and rejects the private workspace version', () => {
const pattern = expectedPublicKtxVersionPattern();
assert.match(`${PUBLIC_NPM_PACKAGE_NAME} ${PUBLIC_NPM_PACKAGE_VERSION}\n`, pattern);
assert.match(`@kaelio/ktx ${PUBLIC_NPM_PACKAGE_VERSION}\n`, pattern);
assert.doesNotMatch('@kaelio/ktx 0.0.0-private\n', pattern);
});
});

View file

@ -28,9 +28,6 @@ import {
writeArtifactManifest,
} from './package-artifacts.mjs';
const PUBLIC_NPM_TARBALL_NAME = `kaelio-ktx-${PUBLIC_NPM_PACKAGE_VERSION}.tgz`;
const RUNTIME_WHEEL_FILE = `kaelio_ktx-${RUNTIME_WHEEL_PACKAGE_VERSION}-py3-none-any.whl`;
async function writeJson(path, value) {
await writeFile(path, `${JSON.stringify(value, null, 2)}\n`);
}
@ -75,6 +72,10 @@ async function writeReleaseMetadataInputs(root) {
}
}
function runtimeWheelFilename(version = RUNTIME_WHEEL_PACKAGE_VERSION) {
return `kaelio_ktx-${version}-py3-none-any.whl`;
}
async function writeUploadableArtifactFixtures(layout) {
await mkdir(layout.npmDir, { recursive: true });
await mkdir(layout.pythonDir, { recursive: true });
@ -84,7 +85,10 @@ async function writeUploadableArtifactFixtures(layout) {
layout.npmTarballs[packageInfo.name],
`${packageInfo.name}-tarball`,
]),
[join(layout.pythonDir, RUNTIME_WHEEL_FILE), 'kaelio-ktx-runtime-wheel'],
[
join(layout.pythonDir, runtimeWheelFilename()),
'kaelio-ktx-runtime-wheel',
],
]);
for (const [path, contents] of fileContents) {
@ -99,7 +103,10 @@ describe('packageArtifactLayout', () => {
assert.equal(layout.artifactDir, '/repo/ktx/dist/artifacts');
assert.equal(layout.npmDir, '/repo/ktx/dist/artifacts/npm');
assert.equal(layout.pythonDir, '/repo/ktx/dist/artifacts/python');
assert.equal(layout.cliTarball, `/repo/ktx/dist/artifacts/npm/${PUBLIC_NPM_TARBALL_NAME}`);
assert.equal(
layout.cliTarball,
`/repo/ktx/dist/artifacts/npm/kaelio-ktx-${PUBLIC_NPM_PACKAGE_VERSION}.tgz`,
);
assert.deepEqual(Object.keys(layout.npmTarballs), ['@kaelio/ktx']);
});
});
@ -154,10 +161,10 @@ describe('findPythonArtifacts', () => {
it('finds the bundled runtime wheel only', async () => {
const root = await mkdtemp(join(tmpdir(), 'ktx-artifacts-test-'));
try {
await writeFile(join(root, RUNTIME_WHEEL_FILE), '');
await writeFile(join(root, runtimeWheelFilename()), '');
assert.deepEqual(await findPythonArtifacts(root), {
runtimeWheel: join(root, RUNTIME_WHEEL_FILE),
runtimeWheel: join(root, runtimeWheelFilename()),
});
} finally {
await rm(root, { recursive: true, force: true });
@ -233,7 +240,7 @@ describe('artifact manifest', () => {
ecosystem: 'npm',
packageName: '@kaelio/ktx',
packageVersion: PUBLIC_NPM_PACKAGE_VERSION,
path: `npm/${PUBLIC_NPM_TARBALL_NAME}`,
path: `npm/kaelio-ktx-${PUBLIC_NPM_PACKAGE_VERSION}.tgz`,
},
],
);
@ -253,12 +260,14 @@ describe('artifact manifest', () => {
ecosystem: 'python',
packageName: 'kaelio-ktx',
packageVersion: RUNTIME_WHEEL_PACKAGE_VERSION,
path: `python/${RUNTIME_WHEEL_FILE}`,
path: `python/${runtimeWheelFilename()}`,
},
],
);
const npmEntry = manifest.files.find((file) => file.path === `npm/${PUBLIC_NPM_TARBALL_NAME}`);
const npmEntry = manifest.files.find(
(file) => file.path === `npm/kaelio-ktx-${PUBLIC_NPM_PACKAGE_VERSION}.tgz`,
);
assert.ok(npmEntry);
assert.equal(npmEntry.bytes, Buffer.byteLength('@kaelio/ktx-tarball'));
assert.equal(npmEntry.sha256, createHash('sha256').update('@kaelio/ktx-tarball').digest('hex'));
@ -361,15 +370,18 @@ describe('copyRuntimeWheelAssets', () => {
const layout = packageArtifactLayout(root, PUBLIC_NPM_PACKAGE_VERSION);
try {
await mkdir(layout.pythonDir, { recursive: true });
await writeFile(join(layout.pythonDir, RUNTIME_WHEEL_FILE), 'kaelio-ktx-runtime-wheel');
await writeFile(
join(layout.pythonDir, runtimeWheelFilename()),
'kaelio-ktx-runtime-wheel',
);
const assets = await copyRuntimeWheelAssets(layout, {
runtimeWheel: join(layout.pythonDir, RUNTIME_WHEEL_FILE),
runtimeWheel: join(layout.pythonDir, runtimeWheelFilename()),
});
assert.equal(
assets.wheelPath,
join(root, 'packages', 'cli', 'assets', 'python', RUNTIME_WHEEL_FILE),
join(root, 'packages', 'cli', 'assets', 'python', runtimeWheelFilename()),
);
assert.equal(
assets.manifestPath,
@ -382,7 +394,7 @@ describe('copyRuntimeWheelAssets', () => {
normalizedName: RUNTIME_WHEEL_NORMALIZED_NAME,
version: RUNTIME_WHEEL_PACKAGE_VERSION,
wheel: {
file: RUNTIME_WHEEL_FILE,
file: runtimeWheelFilename(),
sha256: createHash('sha256')
.update('kaelio-ktx-runtime-wheel')
.digest('hex'),

View file

@ -7,15 +7,13 @@ import { describe, it } from 'node:test';
import {
INTERNAL_NPM_WORKSPACE_PACKAGES,
NPM_ARTIFACT_PACKAGES,
RUNTIME_WHEEL_PACKAGE_VERSION,
packageArtifactLayout,
writeArtifactManifest,
} from './package-artifacts.mjs';
import { PUBLIC_NPM_PACKAGE_VERSION } from './build-public-npm-package.mjs';
import { RUNTIME_WHEEL_PACKAGE_VERSION } from './build-python-runtime-wheel.mjs';
import { readReleasePolicy, releasePolicyPath, releaseReadinessReport } from './release-readiness.mjs';
const RUNTIME_WHEEL_FILE = `kaelio_ktx-${RUNTIME_WHEEL_PACKAGE_VERSION}-py3-none-any.whl`;
async function writeJson(path, value) {
await writeFile(path, `${JSON.stringify(value, null, 2)}\n`);
}
@ -40,7 +38,10 @@ async function writeUploadableArtifactFixtures(layout) {
layout.npmTarballs[packageInfo.name],
`${packageInfo.name}-tarball`,
]),
[join(layout.pythonDir, RUNTIME_WHEEL_FILE), 'kaelio-ktx-runtime-wheel'],
[
join(layout.pythonDir, `kaelio_ktx-${RUNTIME_WHEEL_PACKAGE_VERSION}-py3-none-any.whl`),
'kaelio-ktx-runtime-wheel',
],
]);
for (const [path, contents] of fileContents) {