Skip to content

Commit 4a1a765

Browse files
author
Joel
committed
Address Copilot review: dead code, validation, docs, pagination
- Remove dead mapNotification() from MoltbookProvider (no API endpoint) - Fix malformed UUID examples in Handle.ts doc comments - Fix all 9 social command README test paths (spaces → lowercase slashes) - Fix Handles.expireStale() to paginate through all stale handles - Add UUID format validation to HandleEntity.requestedBy - Add orderBy to short ID resolution for deterministic collision handling - Document in-memory rate limiting as ephemeral by design - Document single-threaded safety for retryCount read-increment-write Skipped by design: credential check-then-insert race (single-persona, tiny window), apiKey format validation (unknown platform formats), 5xx retry logic (project policy: fail clearly, no fallbacks).
1 parent 01aa7b3 commit 4a1a765

File tree

13 files changed

+61
-64
lines changed

13 files changed

+61
-64
lines changed

src/debug/jtag/commands/social/comment/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Test command logic in isolation using mock dependencies:
110110

111111
```bash
112112
# Run unit tests (no server required)
113-
npx tsx commands/Social Comment/test/unit/SocialCommentCommand.test.ts
113+
npx tsx commands/social/comment/test/unit/SocialCommentCommand.test.ts
114114
```
115115

116116
**What's tested:**
@@ -137,7 +137,7 @@ Test command with real client connections and system integration:
137137
npm start # Wait 90+ seconds for deployment
138138

139139
# Run integration tests
140-
npx tsx commands/Social Comment/test/integration/SocialCommentIntegration.test.ts
140+
npx tsx commands/social/comment/test/integration/SocialCommentIntegration.test.ts
141141
```
142142

143143
**What's tested:**

src/debug/jtag/commands/social/community/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Test command logic in isolation using mock dependencies:
123123

124124
```bash
125125
# Run unit tests (no server required)
126-
npx tsx commands/Social Community/test/unit/SocialCommunityCommand.test.ts
126+
npx tsx commands/social/community/test/unit/SocialCommunityCommand.test.ts
127127
```
128128

129129
**What's tested:**
@@ -150,7 +150,7 @@ Test command with real client connections and system integration:
150150
npm start # Wait 90+ seconds for deployment
151151

152152
# Run integration tests
153-
npx tsx commands/Social Community/test/integration/SocialCommunityIntegration.test.ts
153+
npx tsx commands/social/community/test/integration/SocialCommunityIntegration.test.ts
154154
```
155155

156156
**What's tested:**

src/debug/jtag/commands/social/downvote/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Test command logic in isolation using mock dependencies:
102102

103103
```bash
104104
# Run unit tests (no server required)
105-
npx tsx commands/Social Downvote/test/unit/SocialDownvoteCommand.test.ts
105+
npx tsx commands/social/downvote/test/unit/SocialDownvoteCommand.test.ts
106106
```
107107

108108
**What's tested:**
@@ -129,7 +129,7 @@ Test command with real client connections and system integration:
129129
npm start # Wait 90+ seconds for deployment
130130

131131
# Run integration tests
132-
npx tsx commands/Social Downvote/test/integration/SocialDownvoteIntegration.test.ts
132+
npx tsx commands/social/downvote/test/integration/SocialDownvoteIntegration.test.ts
133133
```
134134

135135
**What's tested:**

src/debug/jtag/commands/social/feed/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Test command logic in isolation using mock dependencies:
111111

112112
```bash
113113
# Run unit tests (no server required)
114-
npx tsx commands/Social Feed/test/unit/SocialFeedCommand.test.ts
114+
npx tsx commands/social/feed/test/unit/SocialFeedCommand.test.ts
115115
```
116116

117117
**What's tested:**
@@ -138,7 +138,7 @@ Test command with real client connections and system integration:
138138
npm start # Wait 90+ seconds for deployment
139139

140140
# Run integration tests
141-
npx tsx commands/Social Feed/test/integration/SocialFeedIntegration.test.ts
141+
npx tsx commands/social/feed/test/integration/SocialFeedIntegration.test.ts
142142
```
143143

144144
**What's tested:**

src/debug/jtag/commands/social/notifications/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Test command logic in isolation using mock dependencies:
110110

111111
```bash
112112
# Run unit tests (no server required)
113-
npx tsx commands/Social Notifications/test/unit/SocialNotificationsCommand.test.ts
113+
npx tsx commands/social/notifications/test/unit/SocialNotificationsCommand.test.ts
114114
```
115115

116116
**What's tested:**
@@ -137,7 +137,7 @@ Test command with real client connections and system integration:
137137
npm start # Wait 90+ seconds for deployment
138138

139139
# Run integration tests
140-
npx tsx commands/Social Notifications/test/integration/SocialNotificationsIntegration.test.ts
140+
npx tsx commands/social/notifications/test/integration/SocialNotificationsIntegration.test.ts
141141
```
142142

143143
**What's tested:**

src/debug/jtag/commands/social/post/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Test command logic in isolation using mock dependencies:
105105

106106
```bash
107107
# Run unit tests (no server required)
108-
npx tsx commands/Social Post/test/unit/SocialPostCommand.test.ts
108+
npx tsx commands/social/post/test/unit/SocialPostCommand.test.ts
109109
```
110110

111111
**What's tested:**
@@ -132,7 +132,7 @@ Test command with real client connections and system integration:
132132
npm start # Wait 90+ seconds for deployment
133133

134134
# Run integration tests
135-
npx tsx commands/Social Post/test/integration/SocialPostIntegration.test.ts
135+
npx tsx commands/social/post/test/integration/SocialPostIntegration.test.ts
136136
```
137137

138138
**What's tested:**

src/debug/jtag/commands/social/profile/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Test command logic in isolation using mock dependencies:
116116

117117
```bash
118118
# Run unit tests (no server required)
119-
npx tsx commands/Social Profile/test/unit/SocialProfileCommand.test.ts
119+
npx tsx commands/social/profile/test/unit/SocialProfileCommand.test.ts
120120
```
121121

122122
**What's tested:**
@@ -143,7 +143,7 @@ Test command with real client connections and system integration:
143143
npm start # Wait 90+ seconds for deployment
144144

145145
# Run integration tests
146-
npx tsx commands/Social Profile/test/integration/SocialProfileIntegration.test.ts
146+
npx tsx commands/social/profile/test/integration/SocialProfileIntegration.test.ts
147147
```
148148

149149
**What's tested:**

src/debug/jtag/commands/social/signup/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Test command logic in isolation using mock dependencies:
108108

109109
```bash
110110
# Run unit tests (no server required)
111-
npx tsx commands/Social Signup/test/unit/SocialSignupCommand.test.ts
111+
npx tsx commands/social/signup/test/unit/SocialSignupCommand.test.ts
112112
```
113113

114114
**What's tested:**
@@ -135,7 +135,7 @@ Test command with real client connections and system integration:
135135
npm start # Wait 90+ seconds for deployment
136136

137137
# Run integration tests
138-
npx tsx commands/Social Signup/test/integration/SocialSignupIntegration.test.ts
138+
npx tsx commands/social/signup/test/integration/SocialSignupIntegration.test.ts
139139
```
140140

141141
**What's tested:**

src/debug/jtag/commands/social/trending/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Test command logic in isolation using mock dependencies:
116116

117117
```bash
118118
# Run unit tests (no server required)
119-
npx tsx commands/Social Trending/test/unit/SocialTrendingCommand.test.ts
119+
npx tsx commands/social/trending/test/unit/SocialTrendingCommand.test.ts
120120
```
121121

122122
**What's tested:**
@@ -143,7 +143,7 @@ Test command with real client connections and system integration:
143143
npm start # Wait 90+ seconds for deployment
144144

145145
# Run integration tests
146-
npx tsx commands/Social Trending/test/integration/SocialTrendingIntegration.test.ts
146+
npx tsx commands/social/trending/test/integration/SocialTrendingIntegration.test.ts
147147
```
148148

149149
**What's tested:**

src/debug/jtag/system/core/shared/Handles.ts

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,11 @@ export const Handles = {
137137

138138
// Query all handles and filter by suffix
139139
// The $regex operator matches UUIDs ending with the short ID
140+
// Order by createdAt desc so the most recent match wins on collision
140141
const result = await DataList.execute<HandleEntity>({
141142
collection: COLLECTIONS.HANDLES,
142143
filter: { id: { $regex: `${shortId}$` } },
144+
orderBy: [{ field: 'createdAt', direction: 'desc' }],
143145
limit: 2, // Get 2 to detect ambiguity
144146
});
145147

@@ -267,37 +269,44 @@ export const Handles = {
267269

268270
/**
269271
* Expire all handles past their TTL. Call periodically (e.g., every 60s).
270-
* Returns the number of handles expired.
272+
* Processes in batches of 200 until all stale handles are expired.
273+
* Returns the total number of handles expired.
271274
*/
272275
async expireStale(): Promise<number> {
273276
const now = new Date().toISOString();
277+
let totalExpired = 0;
278+
const BATCH_SIZE = 200;
274279

275-
// Find active handles with expiresAt in the past
276-
const result = await DataList.execute<HandleEntity>({
277-
collection: COLLECTIONS.HANDLES,
278-
filter: {
279-
status: { $in: ['pending', 'processing'] },
280-
expiresAt: { $lte: now },
281-
},
282-
limit: 200,
283-
});
280+
// Loop in batches until no more stale handles remain
281+
while (true) {
282+
const result = await DataList.execute<HandleEntity>({
283+
collection: COLLECTIONS.HANDLES,
284+
filter: {
285+
status: { $in: ['pending', 'processing'] },
286+
expiresAt: { $lte: now },
287+
},
288+
limit: BATCH_SIZE,
289+
});
284290

285-
if (!result.success || !result.items?.length) return 0;
291+
if (!result.success || !result.items?.length) break;
286292

287-
let expired = 0;
288-
for (const entity of result.items) {
289-
try {
290-
await this._updateStatus((entity as HandleEntity).id, 'expired');
291-
expired++;
292-
} catch (err) {
293-
log.warn(`Failed to expire handle ${(entity as HandleEntity).id}: ${err}`);
293+
for (const entity of result.items) {
294+
try {
295+
await this._updateStatus((entity as HandleEntity).id, 'expired');
296+
totalExpired++;
297+
} catch (err) {
298+
log.warn(`Failed to expire handle ${(entity as HandleEntity).id}: ${err}`);
299+
}
294300
}
301+
302+
// If we got fewer than BATCH_SIZE, we've processed all of them
303+
if (result.items.length < BATCH_SIZE) break;
295304
}
296305

297-
if (expired > 0) {
298-
log.info(`Expired ${expired} stale handles`);
306+
if (totalExpired > 0) {
307+
log.info(`Expired ${totalExpired} stale handles`);
299308
}
300-
return expired;
309+
return totalExpired;
301310
},
302311

303312
/**
@@ -317,7 +326,8 @@ export const Handles = {
317326
if (extra?.error !== undefined) updates.error = extra.error;
318327
if (extra?.params !== undefined) updates.params = extra.params;
319328
if (status === 'failed') {
320-
// Increment retry count on failure — read current, increment, write back
329+
// Increment retry count on failure — read current, increment, write back.
330+
// Safe: Node.js is single-threaded, so no concurrent failures for the same handle.
321331
const current = await DataRead.execute<HandleEntity>({
322332
collection: COLLECTIONS.HANDLES,
323333
id,

0 commit comments

Comments
 (0)