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 apps/mobile/src/features/threads/SecretRequestCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function PendingSecretRequestForm(props: {
void send({ type: "reference", source, reference });
}
};
const draft = source === null ? secret : reference;
const draft = source === null ? secret : reference.trim();
const link = secretRequestLink(item);

return (
Expand Down Expand Up @@ -219,7 +219,7 @@ function PendingSecretRequestForm(props: {
label="Save securely"
tone="primary"
fullWidth
disabled={submitting || draft.trim().length === 0}
disabled={submitting || draft.length === 0}
onPress={save}
/>
<View className="flex-row items-center justify-between gap-2">
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/chat/SecretRequestCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function PendingSecretRequestForm(props: {
void send({ type: "reference", source, reference });
}
};
const draft = source === null ? secret : reference;
const draft = source === null ? secret : reference.trim();
const link = secretRequestLink(item);
const describedBy = error !== null ? `${privacyId} ${errorId}` : privacyId;

Expand Down Expand Up @@ -222,7 +222,7 @@ function PendingSecretRequestForm(props: {
/>
)}
</div>
<Button type="submit" disabled={submitting || draft.trim().length === 0}>
<Button type="submit" disabled={submitting || draft.length === 0}>
Save securely
</Button>
</div>
Expand Down
27 changes: 27 additions & 0 deletions packages/client-runtime/src/secretRequest.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {
SecretRequestAnswerInput,
SecretProviderId,
SecretProviderKind,
SecretRequestError,
ThreadId,
TurnItemId,
} from "@t3tools/contracts";
import * as Schema from "effect/Schema";
import { describe, expect, it } from "vite-plus/test";

import {
Expand All @@ -16,6 +18,8 @@ import {
secretRequestSources,
} from "./secretRequest.ts";

const decodeAnswerInput = Schema.decodeUnknownSync(SecretRequestAnswerInput);

describe("secretRequestDisplay", () => {
it("never offers the form for a request inherited from another thread", () => {
expect(secretRequestDisplay({ secretStatus: "pending" }, "inherited")).toEqual({
Expand All @@ -35,6 +39,29 @@ describe("secretRequestPrivacyNote", () => {
});
});

describe("secretRequestAnswerInput", () => {
const item = { id: TurnItemId.make("item-1"), threadId: ThreadId.make("thread-1") };
const savedSecret = (secret: string) => {
const input = secretRequestAnswerInput(item, { type: "save", secret });
if (input === null) return null;
const delivered = decodeAnswerInput(input).answer;
return delivered.type === "save" ? delivered.secret : null;
};

it("delivers the secret exactly as typed, whitespace included", () => {
expect(savedSecret(" pass word ")).toBe(" pass word ");
expect(savedSecret(" ")).toBe(" ");
expect(savedSecret("")).toBeNull();
expect(() =>
decodeAnswerInput({
threadId: item.threadId,
turnItemId: item.id,
answer: { type: "save", secret: "" },
}),
).toThrow();
});
});

describe("secretRequestLink", () => {
it.each([
[
Expand Down
2 changes: 1 addition & 1 deletion packages/client-runtime/src/secretRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export function secretRequestAnswerInput(
? null
: { threadId: item.threadId, turnItemId: item.id, answer: { type: "reference", reference } };
}
const secret = answer.secret.trim();
const { secret } = answer;
if (secret.length === 0) return null;
return { threadId: item.threadId, turnItemId: item.id, answer: { type: "save", secret } };
}
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/src/secretRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Schema from "effect/Schema";

import { ThreadId, TrimmedNonEmptyString, TurnItemId } from "./baseSchemas.ts";
import { ThreadId, TurnItemId } from "./baseSchemas.ts";
import { SecretReference } from "./secretReference.ts";

/** The http(s) page a secret card may open, or null for anything else. */
Expand All @@ -19,7 +19,7 @@ export const SecretRequestAnswerInput = Schema.Struct({
threadId: ThreadId,
turnItemId: TurnItemId,
answer: Schema.Union([
Schema.Struct({ type: Schema.Literal("save"), secret: TrimmedNonEmptyString }),
Schema.Struct({ type: Schema.Literal("save"), secret: Schema.NonEmptyString }),
Schema.Struct({ type: Schema.Literal("decline") }),
/** Read once through a configured secret provider; only servers advertising `secretRequestReferences` accept it. */
Schema.Struct({ type: Schema.Literal("reference"), reference: SecretReference }),
Expand Down
Loading