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
41 changes: 36 additions & 5 deletions apps/cli/src/caps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@ struct LoomImportArgs {
format: OutputFormat,
}

fn loom_import_payload(loom_url: &str, owner_email: Option<&str>, space: Option<&str>) -> Value {
let mut payload = json!({ "loomUrl": loom_url });
if let Some(owner_email) = owner_email {
payload["ownerEmail"] = json!(owner_email);
}
if let Some(space) = space {
payload["spaceName"] = json!(space);
}
payload
}

#[derive(Args)]
struct WaitArgs {
cap: String,
Expand Down Expand Up @@ -1274,11 +1285,11 @@ impl CapsArgs {
.mutate_json_confirmed(
Method::POST,
&format!("/organizations/{organization}/imports/loom"),
&json!({
"loomUrl": args.loom_url,
"ownerEmail": args.owner_email,
"spaceName": args.space,
}),
&loom_import_payload(
&args.loom_url,
args.owner_email.as_deref(),
args.space.as_deref(),
),
)
.await?;
let value = if args.wait {
Expand Down Expand Up @@ -1763,6 +1774,26 @@ mod tests {
use super::*;
use tokio::io::{AsyncReadExt, AsyncWriteExt};

#[test]
fn loom_import_payload_omits_unset_optional_fields() {
assert_eq!(
loom_import_payload("https://www.loom.com/share/abc", None, None),
json!({ "loomUrl": "https://www.loom.com/share/abc" })
);
assert_eq!(
loom_import_payload(
"https://www.loom.com/share/abc",
Some("owner@example.com"),
Some("Team"),
),
json!({
"loomUrl": "https://www.loom.com/share/abc",
"ownerEmail": "owner@example.com",
"spaceName": "Team",
})
);
}

async fn read_request(stream: &mut tokio::net::TcpStream) -> String {
let mut bytes = Vec::new();
let mut buffer = [0_u8; 1_024];
Expand Down
20 changes: 20 additions & 0 deletions apps/web/__tests__/unit/agent-api-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ const status = {
};

describe("agent API contract", () => {
it("accepts omitted and null Loom import options from installed clients", () => {
const loomUrl = "https://www.loom.com/share/synthetic";
const decode = Schema.decodeUnknownSync(Agent.AgentLoomImportInput);

expect(decode({ loomUrl })).toEqual({ loomUrl });
expect(decode({ loomUrl, ownerEmail: null, spaceName: null })).toEqual({
loomUrl,
ownerEmail: null,
spaceName: null,
});
expect(
decode({
loomUrl,
ownerEmail: "owner@example.com",
spaceName: "Team",
}),
).toEqual({ loomUrl, ownerEmail: "owner@example.com", spaceName: "Team" });
expect(() => decode({ loomUrl, ownerEmail: 42 })).toThrow();
});

it("verifies credentials online and rate limits authorization boundaries", () => {
const contract = readFileSync(
join(process.cwd(), "../../packages/web-domain/src/Agent.ts"),
Expand Down
4 changes: 2 additions & 2 deletions packages/web-domain/src/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1132,8 +1132,8 @@ export const AgentUploadCompleteResponse = Schema.Struct({

export const AgentLoomImportInput = Schema.Struct({
loomUrl: Schema.String,
ownerEmail: Schema.optional(Schema.String),
spaceName: Schema.optional(Schema.String),
ownerEmail: Schema.optional(Schema.NullOr(Schema.String)),
spaceName: Schema.optional(Schema.NullOr(Schema.String)),
});

export const AgentProfileUpdateInput = Schema.Struct({
Expand Down
Loading