Repository navigation
Accept campaign channels and promoted subject links #1020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sidneyswift
wants to merge
4
commits into
main
Choose a base branch
from
claude/ctx-2138-campaign-promoted-links
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
eb16932
Accept campaign channels and promoted subject links
sidneyswift b404e86
Match database channel normalization at the campaign brief boundary
sidneyswift c33d7b9
Accept X as a channel and reject URI-scheme channel names
sidneyswift 4de1247
State the campaign channel link check precisely
sidneyswift File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { campaignBriefSchema } from "../campaignBriefSchema"; | ||
|
|
||
| // Hex letters make the upper-case duplicate check below meaningful. | ||
| const requestId = "00000000-0000-4000-a000-0000000000aa"; | ||
| const subjectId = "00000000-0000-4000-a000-0000000000bb"; | ||
| const brief = { name: "Release campaign", goal: "Promote the single" }; | ||
|
|
||
| function failure(input: unknown) { | ||
| const parsed = campaignBriefSchema.safeParse(input); | ||
| if (parsed.success) throw new Error(`Expected rejection: ${JSON.stringify(input)}`); | ||
| return parsed.error.issues.map(issue => `${issue.path.join(".")}: ${issue.message}`).join("\n"); | ||
| } | ||
|
|
||
| describe("campaignBriefSchema", () => { | ||
| it("accepts channels and already-saved promoted subjects, keeping the brief shape", () => { | ||
| const parsed = campaignBriefSchema.parse({ | ||
| ...brief, | ||
| audience: "Existing listeners", | ||
| start_date: "2026-10-01", | ||
| end_date: "2026-10-31", | ||
| channels: [" Short-form video ", "Radio", "X"], | ||
| promoted: [{ request_id: requestId, subject_id: subjectId }], | ||
| }); | ||
| expect(parsed.channels).toEqual(["Short-form video", "Radio", "X"]); | ||
| expect(parsed.promoted).toEqual([{ request_id: requestId, subject_id: subjectId }]); | ||
| }); | ||
|
|
||
| it("leaves a legacy brief without channels or promoted keys untouched", () => { | ||
| const parsed = campaignBriefSchema.parse(brief); | ||
| expect(Object.keys(parsed)).toEqual(["name", "goal"]); | ||
| expect(campaignBriefSchema.safeParse({ ...brief, channels: [], promoted: [] }).success).toBe( | ||
| true, | ||
| ); | ||
| }); | ||
|
|
||
| it("rejects ambiguous links instead of guessing what is promoted", () => { | ||
| expect(failure({ ...brief, promoted_url: "https://example.com/release" })).toMatch( | ||
| /promoted_url/, | ||
| ); | ||
| expect(failure({ ...brief, promoted: ["https://example.com/release"] })).toMatch(/promoted/); | ||
| expect(failure({ ...brief, promoted: [{ url: "https://example.com/release" }] })).toMatch( | ||
| /request_id|subject_id|url/, | ||
| ); | ||
| expect( | ||
| failure({ | ||
| ...brief, | ||
| promoted: [{ request_id: requestId, subject_id: subjectId, url: "https://example.com" }], | ||
| }), | ||
| ).toMatch(/url/); | ||
| expect( | ||
| failure({ ...brief, promoted: [{ request_id: "spotify:album:1", subject_id: subjectId }] }), | ||
| ).toMatch(/request_id/); | ||
| expect(failure({ ...brief, channels: ["https://example.com/channel"] })).toMatch( | ||
| /Channels are names/, | ||
| ); | ||
| expect(failure({ ...brief, channels: ["www.example.com"] })).toMatch(/Channels are names/); | ||
| expect(failure({ ...brief, channels: ["mailto:team@example.com"] })).toMatch( | ||
| /Channels are names/, | ||
| ); | ||
| expect(failure({ ...brief, channels: ["spotify:album:example"] })).toMatch( | ||
| /Channels are names/, | ||
| ); | ||
| }); | ||
|
|
||
| it("rejects private file references; material intake is a separate action", () => { | ||
| expect(failure({ ...brief, file_path: "/private/artwork.png" })).toMatch(/file_path/); | ||
| expect(failure({ ...brief, assets: ["artwork.png"] })).toMatch(/assets/); | ||
| expect(failure({ ...brief, channels: ["/private/plan.pdf"] })).toMatch(/Channels are names/); | ||
| expect(failure({ ...brief, channels: ["file:plan.pdf"] })).toMatch(/Channels are names/); | ||
| expect(failure({ ...brief, channels: ["C:\\plans\\brief.pdf"] })).toMatch(/Channels are names/); | ||
| }); | ||
|
|
||
| it("catches obvious links only, as documented; channel names are never fetched or linked", () => { | ||
| const parsed = campaignBriefSchema.parse({ | ||
| ...brief, | ||
| channels: ["example.com/release", "plan.pdf"], | ||
| }); | ||
| expect(parsed.channels).toEqual(["example.com/release", "plan.pdf"]); | ||
| expect(parsed.promoted).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("requires distinct bounded channels and promoted pairs", () => { | ||
| expect(failure({ ...brief, channels: ["TikTok", "tiktok "] })).toMatch(/distinct/); | ||
| expect( | ||
| failure({ ...brief, channels: Array.from({ length: 11 }, (_, i) => `channel ${i}`) }), | ||
| ).toMatch(/channels/); | ||
| expect(failure({ ...brief, channels: [" "] })).toMatch(/channels/); | ||
| // The database collapses inner whitespace before comparing, so the boundary must agree. | ||
| expect(failure({ ...brief, channels: ["Short form video", "short form video"] })).toMatch( | ||
| /distinct/, | ||
| ); | ||
| expect(failure({ ...brief, channels: ["Radio\tpress"] })).toMatch(/control characters/); | ||
| expect( | ||
| failure({ | ||
| ...brief, | ||
| promoted: [ | ||
| { request_id: requestId, subject_id: subjectId }, | ||
| { request_id: requestId.toUpperCase(), subject_id: subjectId }, | ||
| ], | ||
| }), | ||
| ).toMatch(/distinct/); | ||
| expect( | ||
| failure({ | ||
| ...brief, | ||
| promoted: Array.from({ length: 21 }, (_, i) => ({ | ||
| request_id: requestId, | ||
| subject_id: `00000000-0000-4000-8000-${String(i).padStart(12, "0")}`, | ||
| })), | ||
| }), | ||
| ).toMatch(/promoted/); | ||
| }); | ||
|
|
||
| it("keeps the date ordering rule", () => { | ||
| expect(failure({ ...brief, start_date: "2026-10-31", end_date: "2026-10-01" })).toMatch( | ||
| /end date/, | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import { z } from "zod"; | ||
|
|
||
| // Obvious links only: scheme URLs, URI schemes (mailto:, spotify:, file:), www. hosts, and absolute, home or | ||
| // drive paths. Not a full URL or file detector; channel names are never fetched. Matches the database check. | ||
| const CHANNEL_LINK_PATTERN = /:\/\/|^(?:www\.|\/|\\|~\/)|^[a-z][a-z0-9+.-]*:\S/i; | ||
| const CHANNEL_MESSAGE = | ||
| "Channels are names, not links or files; save promoted records first and reference them in promoted"; | ||
| // Matches the database: control characters are rejected and inner whitespace is collapsed before comparing. | ||
| const CONTROL_CHARACTER_PATTERN = /\p{Cc}/u; | ||
| const channelKey = (value: string) => value.replace(/\s+/g, " ").toLowerCase(); | ||
|
|
||
| const promotedSubjectSchema = z.strictObject({ | ||
| request_id: z.uuid(), | ||
| subject_id: z.uuid(), | ||
| }); | ||
|
|
||
| /** | ||
| * Structured campaign brief accepted by `ingest_campaign_brief`. | ||
| * Promoted entries are only `{request_id, subject_id}` pairs the workspace already saved; the database | ||
| * verifies each pair. Channel names that look like links are rejected here, before authorization. | ||
| */ | ||
| export const campaignBriefSchema = z | ||
| .strictObject({ | ||
| name: z.string().trim().min(2).max(200), | ||
| goal: z.string().trim().min(2).max(2000), | ||
| audience: z.string().trim().max(500).optional(), | ||
| start_date: z.iso.date().optional(), | ||
| end_date: z.iso.date().optional(), | ||
| channels: z | ||
| .array( | ||
| z | ||
| .string() | ||
| .trim() | ||
| .min(1) | ||
| .max(60) | ||
| .refine(value => !CONTROL_CHARACTER_PATTERN.test(value), { | ||
| message: "Channel names must not contain control characters", | ||
| }) | ||
| .refine(value => !CHANNEL_LINK_PATTERN.test(value), { message: CHANNEL_MESSAGE }), | ||
| ) | ||
| .max(10) | ||
| .refine(values => new Set(values.map(channelKey)).size === values.length, { | ||
| message: "Campaign channels must be distinct", | ||
| }) | ||
| .optional(), | ||
| promoted: z | ||
| .array(promotedSubjectSchema) | ||
| .max(20) | ||
| .refine( | ||
| values => | ||
| new Set(values.map(value => `${value.request_id}:${value.subject_id}`.toLowerCase())) | ||
| .size === values.length, | ||
| { message: "Promoted subjects must be distinct" }, | ||
| ) | ||
| .optional(), | ||
| }) | ||
| .refine(value => !value.start_date || !value.end_date || value.end_date >= value.start_date, { | ||
| message: "Campaign end date must not precede start date", | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: Custom agent: Enforce Clear Code Style and Maintainability Practices
This test file has grown to 139 lines with the three new link-related cases, over the 100-line cap in the Maintainability guideline. Move the
promotedfixture and the new test cases into a dedicated file such aslib/context/__tests__/campaignBriefLinks.test.tsto keep each file under the limit and preserve single-responsibility organization.Prompt for AI agents