Skip to content
Merged
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
38 changes: 38 additions & 0 deletions apps/server/src/auth/PairingGrantStore.lastcode.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
import * as NodeServices from "@effect/platform-node/NodeServices";
import { expect, it } from "@effect/vitest";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";

import * as ServerConfig from "../config.ts";
import * as SqlitePersistence from "../persistence/Sqlite.ts";
import * as PairingGrantStore from "./PairingGrantStore.ts";

const layerPairingGrantStore = () =>
PairingGrantStore.layer.pipe(
Layer.provide(SqlitePersistence.layerMemory),
Layer.provide(ServerConfig.layerTest(process.cwd(), { prefix: "t3-auth-bootstrap-test-" })),
);

it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("PairingGrantStore.layer", (it) => {
it.effect.each([
{ label: "empty", requestedScopes: [] },
{ label: "ungranted", requestedScopes: ["access:write"] },
] as const)("preserves a one-time grant after an $label scope request", ({ requestedScopes }) =>
Effect.gen(function* () {
const bootstrapCredentials = yield* PairingGrantStore.PairingGrantStore;
const token = yield* bootstrapCredentials.issueOneTimeToken({
scopes: ["orchestration:read"],
});
const rejected = yield* Effect.flip(
bootstrapCredentials.consume(token.credential, { requestedScopes }),
);
expect(rejected._tag).toBe("BootstrapCredentialScopeNotGrantedError");

const consumed = yield* bootstrapCredentials.consume(token.credential);
expect(consumed.scopes).toEqual(["orchestration:read"]);
const reused = yield* Effect.flip(bootstrapCredentials.consume(token.credential));
expect(reused._tag).toBe("UnknownBootstrapCredentialError");
}).pipe(Effect.provide(layerPairingGrantStore())),
);
});
21 changes: 0 additions & 21 deletions apps/server/src/auth/PairingGrantStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,6 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("PairingGrantStor
}).pipe(Effect.provide(layerPairingGrantStore())),
);

it.effect.each([
{ label: "empty", requestedScopes: [] },
{ label: "ungranted", requestedScopes: ["access:write"] },
] as const)("preserves a one-time grant after an $label scope request", ({ requestedScopes }) =>
Effect.gen(function* () {
const bootstrapCredentials = yield* PairingGrantStore.PairingGrantStore;
const token = yield* bootstrapCredentials.issueOneTimeToken({
scopes: ["orchestration:read"],
});
const rejected = yield* Effect.flip(
bootstrapCredentials.consume(token.credential, { requestedScopes }),
);
expect(rejected._tag).toBe("BootstrapCredentialScopeNotGrantedError");

const consumed = yield* bootstrapCredentials.consume(token.credential);
expect(consumed.scopes).toEqual(["orchestration:read"]);
const reused = yield* Effect.flip(bootstrapCredentials.consume(token.credential));
expect(reused._tag).toBe("UnknownBootstrapCredentialError");
}).pipe(Effect.provide(layerPairingGrantStore())),
);

it.effect("requires the bound proof key thumbprint when present", () =>
Effect.gen(function* () {
const bootstrapCredentials = yield* PairingGrantStore.PairingGrantStore;
Expand Down
28 changes: 28 additions & 0 deletions apps/server/src/http.lastcode.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { expect, it } from "@effect/vitest";
import * as NodeHttpPlatform from "@effect/platform-node/NodeHttpPlatform";
import * as NodeServices from "@effect/platform-node/NodeServices";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
import * as Path from "effect/Path";
import { HttpServerResponse } from "effect/http";

import { assetFileResponse } from "./http.ts";

const layerFileResponse = Layer.mergeAll(NodeHttpPlatform.layer, NodeServices.layer);

it.effect("keeps attachment media out of the cache once its signed URL expires", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const directory = yield* fs.makeTempDirectoryScoped({ prefix: "t3-attachment-media-" });
const filePath = path.join(directory, "audio.wav");
yield* fs.writeFileString(filePath, "RIFF");
const canonicalPath = yield* fs.realPath(filePath);
const response = HttpServerResponse.toWeb(
yield* assetFileResponse({ path: canonicalPath, mimeType: "audio/wav" }),
);
expect(response.headers.get("cache-control")).toBe("private, no-store, no-transform");
expect(response.headers.get("accept-ranges")).toBe("bytes");
}).pipe(Effect.provide(layerFileResponse)),
);
16 changes: 0 additions & 16 deletions apps/server/src/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,22 +708,6 @@ describe("video asset byte ranges", () => {
}).pipe(Effect.provide(layerFileResponse)),
);

it.effect("keeps attachment media out of the cache once its signed URL expires", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const directory = yield* fs.makeTempDirectoryScoped({ prefix: "t3-attachment-media-" });
const filePath = path.join(directory, "audio.wav");
yield* fs.writeFileString(filePath, "RIFF");
const canonicalPath = yield* fs.realPath(filePath);
const response = HttpServerResponse.toWeb(
yield* assetFileResponse({ path: canonicalPath, mimeType: "audio/wav" }),
);
expect(response.headers.get("cache-control")).toBe("private, no-store, no-transform");
expect(response.headers.get("accept-ranges")).toBe("bytes");
}).pipe(Effect.provide(layerFileResponse)),
);

it.effect("closes guarded descriptors after full, HEAD, rejected, and cancelled responses", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import * as Fiber from "effect/Fiber";
import * as Layer from "effect/Layer";
import * as Path from "effect/Path";
import * as Ref from "effect/Ref";
import * as Schema from "effect/Schema";
import * as Stream from "effect/Stream";
import { ChildProcessSpawner } from "effect/process";
import type * as EffectAcpSchema from "effect-acp/compat";
Expand All @@ -44,8 +43,6 @@ import {
makeAntigravityAdapterV2,
} from "./AntigravityAdapterV2.ts";

const isAcpRequestError = Schema.is(EffectAcpErrors.AcpRequestError);

const flavor = makeAntigravityAcpAdapterFlavor({
instanceId: ProviderInstanceId.make("antigravity-test"),
random: undefined as never,
Expand Down Expand Up @@ -375,27 +372,6 @@ describe("AntigravityAdapterV2 client file system", () => {
const insidePath = path.join(workspace, "src", "inside.ts");
yield* fileSystem.makeDirectory(path.dirname(insidePath), { recursive: true });
yield* fileSystem.writeFileString(insidePath, "inside");
const workspaceAlias = path.join(outside, "workspace-alias");
yield* fileSystem.symlink(workspace, workspaceAlias);
const nestedPath = path.join(workspaceAlias, "new", "nested", "inside.ts");
const missingRead = yield* readTextFile(
{ sessionId: "mock-session-1", path: nestedPath },
context("fs/read_text_file"),
).pipe(Effect.flip);
assert.equal(
isAcpRequestError(missingRead) && missingRead.code,
EffectAcpErrors.AcpRequestError.resourceNotFound("missing").code,
);
yield* fileSystem.makeDirectory(path.join(workspace, "new", "nested"), { recursive: true });
yield* fileSystem.writeFileString(
path.join(workspace, "new", "nested", "inside.ts"),
"nested",
);
const nestedRead = yield* readTextFile(
{ sessionId: "mock-session-1", path: nestedPath },
context("fs/read_text_file"),
);
assert.equal(nestedRead.content, "nested");
const pasted = yield* readTextFile(
{ sessionId: "mock-session-1", path: attachment },
context("fs/read_text_file"),
Expand Down
Loading
Loading