Initial Commit
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
import { mkdtempSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { Drive } from "@suaveplan/drive";
|
||||
import { createNodeFsStorage } from "@suaveplan/storage-file";
|
||||
import { createStorageUriResolver } from "@suaveplan/storage-uri";
|
||||
import {
|
||||
afterEach,
|
||||
beforeEach,
|
||||
describe,
|
||||
expect,
|
||||
it,
|
||||
} from "@suaveplan/testing/runner";
|
||||
import {
|
||||
DRIVE_URI_CODES,
|
||||
DriveUriError,
|
||||
} from "../../src/error-codes/error-codes.js";
|
||||
import { driveTemplateUriPlugin } from "../../src/plugins/drive-template/drive-template.js";
|
||||
|
||||
describe("template-roundtrip integration", () => {
|
||||
let rootDir: string;
|
||||
let drive: Drive;
|
||||
|
||||
beforeEach(async () => {
|
||||
rootDir = mkdtempSync(join(tmpdir(), "drive-uri-template-"));
|
||||
const fileStorage = createNodeFsStorage({ rootDir, mkdirp: true });
|
||||
const storage = Object.assign(fileStorage, { id: "default" });
|
||||
drive = new Drive(storage);
|
||||
await drive.initialize();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await drive.dispose();
|
||||
rmSync(rootDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it("real Drive.hydrateFrom rejects unsigned template as TEMPLATE_INVALID", {
|
||||
timeout: 30000,
|
||||
}, async () => {
|
||||
const provider = {
|
||||
async fetchTemplate(): Promise<unknown> {
|
||||
// Returning an obviously-malformed template forces
|
||||
// Drive.hydrateFrom's validation pipeline to reject.
|
||||
return {};
|
||||
},
|
||||
};
|
||||
const plugin = driveTemplateUriPlugin({
|
||||
drive,
|
||||
templateProvider: provider as unknown as Parameters<
|
||||
typeof driveTemplateUriPlugin
|
||||
>[0]["templateProvider"],
|
||||
});
|
||||
const resolver = createStorageUriResolver([plugin]);
|
||||
try {
|
||||
await resolver.read("drive+template://templA/x");
|
||||
throw new Error("expected throw");
|
||||
} catch (err) {
|
||||
// SuaveplanError subclasses pass through the resolver
|
||||
// unchanged, so the caller sees the DriveUriError directly.
|
||||
expect(err).toBeInstanceOf(DriveUriError);
|
||||
const e = err as DriveUriError;
|
||||
expect(e.code).toBe(DRIVE_URI_CODES.TEMPLATE_INVALID);
|
||||
// The inner cause is the real DTP_*/DRIVE error surfaced by
|
||||
// Drive's hydrateFrom — confirming the wrapping path is wired
|
||||
// through real package code, not a stub.
|
||||
expect(e.cause).toBeDefined();
|
||||
}
|
||||
});
|
||||
|
||||
it("provider rejection becomes TEMPLATE_NOT_AVAILABLE via real Drive", {
|
||||
timeout: 30000,
|
||||
}, async () => {
|
||||
const original = new Error("network down");
|
||||
const provider = {
|
||||
async fetchTemplate(): Promise<never> {
|
||||
throw original;
|
||||
},
|
||||
};
|
||||
const plugin = driveTemplateUriPlugin({
|
||||
drive,
|
||||
templateProvider: provider as unknown as Parameters<
|
||||
typeof driveTemplateUriPlugin
|
||||
>[0]["templateProvider"],
|
||||
});
|
||||
const resolver = createStorageUriResolver([plugin]);
|
||||
try {
|
||||
await resolver.read("drive+template://templA/x");
|
||||
throw new Error("expected throw");
|
||||
} catch (err) {
|
||||
expect(err).toBeInstanceOf(DriveUriError);
|
||||
const e = err as DriveUriError;
|
||||
expect(e.code).toBe(DRIVE_URI_CODES.TEMPLATE_NOT_AVAILABLE);
|
||||
expect(e.cause).toBe(original);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user