UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

125 lines • 6.53 kB
import type { IndexCacheStore } from './cache/index/store.ts'; import type { Handed } from './vfs/types.ts'; import type { NamespaceLinks, OpKwargs } from './view/types.ts'; import type { MountRow } from './workspace/types.ts'; import type { Measured, WriteContext } from './cache/types.ts'; import { type FileStat, PathSpec, type Visibility } from './types.ts'; import { BaseVFS } from './vfs/base.ts'; import { RAMVFS } from './vfs/ram/ram.ts'; import type { Accessor } from './accessor/base.ts'; import { Workspace } from './workspace/workspace/workspace.ts'; import { Files, type FilesOptions } from './workspace/files.ts'; import { NamespaceReader } from './workspace/dispatcher/reader.ts'; import { type ByteSource } from './io/types.ts'; import type { RAMAccessor } from './accessor/ram.ts'; import type { StorageUsage } from './vfs/capacity.ts'; /** A RAM accessor whose store holds at most `cap` bytes. */ export declare function capped(cap: number, files?: Record<string, string>): [RAMAccessor, StorageUsage]; /** A RAM mount path for core calls: `/a/b` keyed as the store keys it. */ export declare function ramPath(virtual: string): PathSpec; /** The bytes a RAM accessor's table holds. */ export declare function tableBytes(accessor: RAMAccessor): number; /** * A VFS called the way a mount calls it: through the dispatcher, one index * store per instance, so a driver can be exercised without a Workspace. A * verb the VFS does not answer is a `no op registered` error, the same * answer a mount gives. */ declare class MountedVFS { readonly vfs: BaseVFS; readonly index: IndexCacheStore; private readonly mount; constructor(vfs: BaseVFS); /** Whether the dispatcher answers `name` on this VFS. */ has(name: string): boolean; /** Call op `name` on `path`; `index` defaults to this instance's store. */ call(name: string, path: PathSpec, args?: readonly unknown[], kwargs?: OpKwargs): Promise<unknown>; read(path: PathSpec, kwargs?: OpKwargs): Promise<Uint8Array>; readdir(path: PathSpec): Promise<string[]>; stat(path: PathSpec): Promise<FileStat>; /** Expand a pattern over this VFS's listings, as a shell glob walks them. */ glob(path: PathSpec): Promise<PathSpec[]>; write(path: PathSpec, data: Uint8Array): Promise<void>; append(path: PathSpec, data: Uint8Array): Promise<void>; create(path: PathSpec): Promise<void>; mkdir(path: PathSpec, parents?: boolean): Promise<void>; unlink(path: PathSpec): Promise<void>; rmdir(path: PathSpec): Promise<void>; rename(src: PathSpec, dst: PathSpec): Promise<void>; truncate(path: PathSpec, length: number): Promise<void>; } /** The dispatcher of `vfs`, bound once per instance so its index store persists across calls. */ export declare function ops(vfs: BaseVFS): MountedVFS; type ReadLike = (path: PathSpec, index?: IndexCacheStore, offset?: number, size?: number | null) => Promise<Uint8Array>; /** * Have this one `vfs` render reads of `filetype` with `fn`, which takes * `read`'s arguments, window included, as a renderer method does. */ export declare function render<V extends BaseVFS>(vfs: V, filetype: string, fn: ReadLike): V; /** * A `cls` VFS over `accessor`, its constructor skipped: the class's functions * with the base facts, so a test drives a backend's functions with an * accessor of its own. A fact the class declares is not set; pass the ones a * test relies on. */ export declare function vfsOver<V extends BaseVFS>(cls: { prototype: V; }, accessor: Accessor, facts?: Partial<Record<keyof V, unknown>>): V; type Answer = (path: PathSpec, args: readonly unknown[], kwargs: OpKwargs) => unknown; /** * Files whose dispatcher answers each op `answers` names, and refuses any * other the way a mount without that function does (ENOTSUP), except * `before_full_walk`, which passes as it does on a mount with no * `walkLimit`: a command's files over a fake backend, for a test that * drives a builder alone. `rows` * is the mount table (`readers`), `links` the namespace's link table. Mirrors * Python's `tests/fixtures/answers.Answers`. */ export declare function answeringFiles(answers: Readonly<Record<string, Answer>>, options?: FilesOptions, rows?: readonly (MountRow | string)[], links?: NamespaceLinks | null): Files; /** * A namespace's readers over a fixed mount table and link table, for files * that stand outside a workspace; a prefix alone stands for a RAM mount * there. Mirrors Python's `tests.fixtures.readers`. */ export declare function readers(rows?: readonly (MountRow | string)[], links?: NamespaceLinks | null, visibility?: Visibility | null): (sessionId: string | null) => NamespaceReader; /** * Run `fn` the way a command on `vfs` runs: `vfs` mounted alone at `prefix` * in a workspace of its own (one per VFS), `fn` handed the workspace's files, * which a command reads and writes through (`ctx.vfs`), inside the mount's * command scope. */ export declare function onMount<T>(vfs: BaseVFS, fn: (files: Files) => Promise<T> | T, prefix?: string): Promise<T>; /** * A write context whose store holds `s0` and records what it keeps, for a * refusal test where the store's version, the write's and the one sent all * differ. Mirrors Python's `tests/fixtures/write_context.KeptVersions`. */ export declare function keptVersions(vfs: string): { context: WriteContext; kept: Measured[]; }; /** * Record every call the workspace's dispatcher serves from now on, by op * name and virtual path: where a line's own I/O is judged. `before` runs * ahead of each call, so a test can hold one mid-command. Mirrors the * Python `dispatched` test fixture. */ export declare function dispatched(ws: Workspace, before?: (name: string, path: PathSpec) => Promise<void>): [string, string][]; /** * A RAM mount standing in for a remote store: it keeps its reads, and reads a * batch in one call where `batched`, counting both. Mirrors the Python * `BatchedRAM` test fixture. */ export declare class BatchedRAM extends RAMVFS { readonly batched: boolean; readonly cachesReads: boolean; readonly local: boolean; readonly reads: string[]; readonly batches: string[][]; constructor(batched?: boolean); supports(name: string): boolean; read(path: PathSpec, handed?: Handed, offset?: number, size?: number | null): Promise<ByteSource> | AsyncIterable<Uint8Array>; readMany(paths: PathSpec[]): Promise<Map<string, Uint8Array>>; } export {}; //# sourceMappingURL=test-utils.d.ts.map