Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/publish-npm-on-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ on:
workflow_dispatch:
inputs:
tag:
description: 'Tag to publish (e.g. v2.2.0)'
description: 'Tag to publish (e.g. v2.3.0)'
required: true
default: 'v2.2.0'
default: 'v2.3.0'

permissions:
contents: read
Expand Down
15 changes: 11 additions & 4 deletions src/core/reranker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ const AMBIGUITY_THRESHOLD = 0.08;

interface CrossEncoderTokenizer {
(
query: string,
passage: string,
options: { padding: boolean; truncation: boolean; max_length: number }
text: string,
options?: {
text_pair?: string | null;
padding?: boolean | 'max_length';
truncation?: boolean | null;
max_length?: number | null;
return_tensor?: boolean;
return_token_type_ids?: boolean | null;
}
): unknown;
}

Expand Down Expand Up @@ -152,7 +158,8 @@ async function scorePair(query: string, passage: string): Promise<number> {
throw new Error('[reranker] Model not loaded — call ensureModelLoaded() first');
}

const inputs = cachedTokenizer(query, passage, {
const inputs = cachedTokenizer(query, {
text_pair: passage,
padding: true,
truncation: true,
max_length: 512
Expand Down
2 changes: 1 addition & 1 deletion src/embeddings/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class TransformersEmbeddingProvider implements EmbeddingProvider {
const { pipeline } = await import('@huggingface/transformers');

// TS2590: pipeline() resolves AllTasks[T] — a union too complex for TSC to represent.
// Cast to a simpler signature; the actual return type IS FeatureExtractionPipelineType.
// Cast to a simpler feature-extraction signature for both v3 and v4-compatible types.
type PipelineFn = (
task: 'feature-extraction',
model: string,
Expand Down
25 changes: 21 additions & 4 deletions tests/contextbench-baseline-schema-gate.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { execFileSync } from 'node:child_process';
import { chmodSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import {
chmodSync,
mkdtempSync,
readFileSync,
realpathSync,
rmSync,
writeFileSync
} from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { describe, expect, it, vi } from 'vitest';
Expand Down Expand Up @@ -55,6 +62,10 @@ function cleanupSessionRoot(sessionRoot: string): void {
}
}

function normalizeFilesystemPath(filePath: string): string {
return realpathSync(filePath);
}

function tempSessionRoot(phase: 'phase40' | 'phase41' = 'phase40'): string {
return path.join(
mkdtempSync(path.join(tmpdir(), `contextbench-${phase}-schema-gate-`)),
Expand Down Expand Up @@ -398,7 +409,9 @@ describe('ContextBench Phase 40 schema gate', () => {
repoCheckoutPath: repoPath,
verificationStrict: false
});
expect(readFileSync(cwdCapturePath, 'utf8')).toBe(repoPath);
expect(normalizeFilesystemPath(readFileSync(cwdCapturePath, 'utf8'))).toBe(
normalizeFilesystemPath(repoPath)
);
const stdin = readFileSync(stdinCapturePath, 'utf8');
expect(stdin).toContain('Problem statement:');
expect(stdin).toContain('Fix the failing ContextBench task');
Expand Down Expand Up @@ -584,7 +597,9 @@ describe('ContextBench Phase 40 schema gate', () => {
],
{ encoding: 'utf8', env }
);
expect(readFileSync(cwdPath, 'utf8')).toBe(repoPath);
expect(normalizeFilesystemPath(readFileSync(cwdPath, 'utf8'))).toBe(
normalizeFilesystemPath(repoPath)
);
}
execFileSync(
'node',
Expand Down Expand Up @@ -681,7 +696,9 @@ describe('ContextBench Phase 40 schema gate', () => {
(candidate) => candidate.scoring && 'baselineArmId' in candidate.scoring
);
expect(row).toMatchObject({ status: 'completed' });
expect(readFileSync(cwdCapturePath, 'utf8')).toBe(repoPath);
expect(normalizeFilesystemPath(readFileSync(cwdCapturePath, 'utf8'))).toBe(
normalizeFilesystemPath(repoPath)
);
const stdin = readFileSync(stdinCapturePath, 'utf8');
expect(stdin).toContain('Problem statement:');
expect(stdin).toContain('Run the diagnostic arm with materialized task text.');
Expand Down
14 changes: 7 additions & 7 deletions tests/release-truth-surfaces.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ function extractMarkdownLinks(markdown: string): string[] {
describe('release truth surfaces', () => {
const packageJson = readJson<PackageJson>('package.json');
const releaseManifest = readJson<ReleaseManifest>('.release-please-manifest.json');
const expectedVersion = packageJson.version;
const changelog = readText('CHANGELOG.md');
const readme = readText('README.md');
const workflow = readText('.github/workflows/publish-npm-on-release.yml');
const todoDoc = readOptionalText('docs/TODO.md');
const visualsDoc = readOptionalText('docs/visuals.md');
const packagedPaths = ['README.md', 'LICENSE', ...(packageJson.files ?? [])];

it('keeps package metadata, release manifest, and changelog on 2.2.0', () => {
expect(packageJson.version).toBe('2.2.0');
expect(releaseManifest['.']).toBe('2.2.0');
expect(changelog).toContain('## [2.2.0]');
it('keeps package metadata, release manifest, and changelog aligned', () => {
expect(releaseManifest['.']).toBe(expectedVersion);
expect(changelog).toContain(`## [${expectedVersion}]`);
expect(changelog).not.toContain('## Unreleased');
});

Expand Down Expand Up @@ -114,8 +114,8 @@ describe('release truth surfaces', () => {
expect(visualsDoc).toContain('Historical snapshot');
});

it('keeps the manual publish fallback aligned to v2.2.0', () => {
expect(workflow).toContain("description: 'Tag to publish (e.g. v2.2.0)'");
expect(workflow).toContain("default: 'v2.2.0'");
it('keeps the manual publish fallback aligned to the package version', () => {
expect(workflow).toContain(`description: 'Tag to publish (e.g. v${expectedVersion})'`);
expect(workflow).toContain(`default: 'v${expectedVersion}'`);
});
});
34 changes: 33 additions & 1 deletion tests/reranker-recovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ describe('reranker corruption recovery', () => {
await fs.mkdir(modelCacheDir, { recursive: true });
await fs.writeFile(path.join(modelCacheDir, 'model.onnx'), 'corrupt');

const tokenizer = vi.fn((query: string, passage: string) => ({ query, passage }));
const tokenizer = vi.fn(
(query: string, options?: { text_pair?: string | null }) => ({
query,
passage: options?.text_pair ?? ''
})
);
Comment thread
aolin480 marked this conversation as resolved.
const model = vi.fn(async (inputs: { passage: string }) => {
if (inputs.passage.includes('/a.ts')) return { logits: { data: [1] } };
if (inputs.passage.includes('/b.ts')) return { logits: { data: [3] } };
Expand All @@ -89,6 +94,33 @@ describe('reranker corruption recovery', () => {
const reranked = await rerank('auth token', results);
expect(transformersMocks.tokenizerFromPretrained).toHaveBeenCalledTimes(2);
expect(transformersMocks.modelFromPretrained).toHaveBeenCalledTimes(2);
expect(tokenizer).toHaveBeenCalledWith(
'auth token',
expect.objectContaining({
text_pair: expect.stringContaining('/a.ts'),
padding: true,
truncation: true,
max_length: 512
})
);
expect(tokenizer).toHaveBeenCalledWith(
'auth token',
expect.objectContaining({
text_pair: expect.stringContaining('/b.ts'),
padding: true,
truncation: true,
max_length: 512
})
);
expect(tokenizer).toHaveBeenCalledWith(
'auth token',
expect.objectContaining({
text_pair: expect.stringContaining('/c.ts'),
padding: true,
truncation: true,
max_length: 512
})
);
Comment thread
aolin480 marked this conversation as resolved.
expect(reranked.map((result) => result.filePath)).toEqual(['/b.ts', '/c.ts', '/a.ts']);
expect(getRerankerStatus()).toBe('active');
});
Expand Down