Skip to content

Commit 09593ce

Browse files
committed
Ensure all children are visited
1 parent cd8d1fc commit 09593ce

File tree

5 files changed

+50
-34
lines changed

5 files changed

+50
-34
lines changed

deno.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/deno.jsonc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lpm/core",
3-
"version": "0.2.8",
3+
"version": "0.2.9",
44
"license": "MIT",
55
"exports": "./mod.ts",
66

packages/core/src/node-registry.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,11 @@ export class NodeRegistry {
6060
for (const resolution of resolutions) {
6161
if (!seenNodeNsids.has(resolution.nsid.toString())) {
6262
yield resolution;
63+
seenNodeNsids.add(resolution.nsid.toString());
6364
if (resolution.success) {
6465
const children = resolution.children.filter(
6566
(nsid) => !seenNodeNsids.has(nsid.toString()),
6667
);
67-
children.forEach((nsid) => {
68-
seenNodeNsids.add(nsid.toString());
69-
});
7068

7169
queue.push(...children);
7270
}

packages/core/src/node.test.ts

+44-29
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { NSID } from "@atproto/syntax";
1+
import { AtUri, NSID } from "@atproto/syntax";
22
import type { Resolution } from "./node.ts";
33
import { NodeRegistry } from "./node-registry.ts";
44
import { assertEquals, assertObjectMatch } from "jsr:@std/assert";
55
import { bootstrap } from "@needle-di/core";
66
import { Lexicons } from "@atproto/lexicon";
7-
import { skip } from "node:test";
7+
import { AtpBaseClient } from "npm:@atproto/api";
88

99
function assertSuccessfullResolution(
1010
data: Resolution,
@@ -93,30 +93,45 @@ Deno.test("doesn't resolve the same uri twice", async () => {
9393
assertEquals(new Set(duplicateUris), new Set());
9494
});
9595

96-
Deno.test,
97-
skip("can validate a post record", async () => {
98-
const NSID_STR = "app.bsky.feed.post";
99-
const registry = bootstrap(NodeRegistry);
100-
const resolutions = [];
101-
for await (
102-
const resolution of registry.resolve([
103-
registry.get(NSID.parse(NSID_STR)),
104-
])
105-
) {
106-
assertSuccessfullResolution(resolution);
107-
resolutions.push(resolution);
108-
}
109-
110-
const lexicons = new Lexicons(resolutions.map((r) => r.doc));
111-
112-
const exampleRecords = [
113-
'{"uri":"at://did:plc:2xau7wbgdq4phuou2ypwuen7/app.bsky.feed.post/3ljrsfbuuyk2g","cid":"bafyreigjrpyhhk5fibcajhhtkcefmxptntgx35t5zngvsxwwvu56hzioaq","value":{"text":"To update a globally installed CLI in deno you pass -fr\\n\\nfr fr","$type":"app.bsky.feed.post","langs":["en"],"createdAt":"2025-03-07T10:28:47.874Z"}}',
114-
'{"uri":"at://did:plc:yosojsta3nm5qiod5zqixzur/app.bsky.feed.post/3ljpreuc6fs2c","cid":"bafyreihyt2ckoxoyusimrexuxatuwazct7uiskukhspxic756inddofipy","value":{"text":"DOGE “seemed unsure” of what USAID programs they cut and is now attempting to reverse some of the cuts, says @propublica.org reporter Brett Murphy. “This is the opposite of a careful review.\\"","$type":"app.bsky.feed.post","embed":{"$type":"app.bsky.embed.video","video":{"$type":"blob","ref":{"$link":"bafkreidowys6ntilo4wslx23jishxiqfrwywqmxxer4sy2r6y5orwuosn4"},"mimeType":"video/mp4","size":8408607},"aspectRatio":{"width":1280,"height":720}},"langs":["en"],"facets":[{"$type":"app.bsky.richtext.facet","index":{"byteEnd":128,"byteStart":113},"features":[{"did":"did:plc:k4jt6heuiamymgi46yeuxtpt","$type":"app.bsky.richtext.facet#mention"}]}],"createdAt":"2025-03-06T15:05:20.412Z"}}',
115-
].map((s) => JSON.parse(s).value);
116-
117-
for (const exampleRecord of exampleRecords) {
118-
const result = lexicons.validate(NSID_STR, exampleRecord);
119-
// @ts-expect-error result.error isn't narrowed
120-
assertEquals(result.success, true, `Failed to validate: ${result.error}`);
121-
}
122-
});
96+
Deno.test("can validate a post record", async () => {
97+
const NSID_STR = "app.bsky.feed.post";
98+
const registry = bootstrap(NodeRegistry);
99+
const resolutions = [];
100+
for await (
101+
const resolution of registry.resolve([
102+
registry.get(NSID.parse(NSID_STR)),
103+
])
104+
) {
105+
assertSuccessfullResolution(resolution);
106+
resolutions.push(resolution);
107+
}
108+
109+
const client = new AtpBaseClient("https://api.bsky.app");
110+
111+
const postUris = [
112+
"at://did:plc:2xau7wbgdq4phuou2ypwuen7/app.bsky.feed.post/3ljmvgixb327d",
113+
].map((uri) => new AtUri(uri));
114+
115+
const records = await Promise.all(
116+
postUris.map((uri) =>
117+
client.com.atproto.repo.getRecord({
118+
repo: uri.host,
119+
collection: uri.collection,
120+
rkey: uri.rkey,
121+
})
122+
),
123+
);
124+
125+
const lexicons = new Lexicons(resolutions.map((r) => r.doc));
126+
127+
for (const record of records) {
128+
const result = lexicons.validate(NSID_STR, record.data.value);
129+
assertEquals(
130+
result.success,
131+
true,
132+
`Failed to validate ${record.data.uri}: ${
133+
// @ts-expect-error result.error isn't narrowed
134+
result.error}`,
135+
);
136+
}
137+
});

packages/core/src/node.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ export class Node {
6666
throw new Error("Expected cid to be defined");
6767
}
6868

69+
const refs = getRefs(doc);
70+
6971
const externalRefs = [
7072
...new Set(
71-
getRefs(doc)
73+
refs
7274
.filter(
7375
(ref) =>
7476
!ref.startsWith("#") &&

0 commit comments

Comments
 (0)