forked from pingdotgg/t3code
-
Notifications
You must be signed in to change notification settings - Fork 0
Sync fork with upstream/main (Effect services, dep bump) #42
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
48fc85e
Bump Effect catalog dependencies (#1594)
juliusmarminge d303ac3
Replace wait-on with internal desktop resource polling (#1600)
juliusmarminge 2d03847
Extract project/workspace related functionality to Effect services (#…
juliusmarminge 1df2037
Merge upstream/main: Effect services extraction, dep bump, desktop po…
aaditagrawal dc85418
Address code review: security hardening, validation, error handling
aaditagrawal 3241c6b
Fix WorkspaceEntries: dotfile queries, basename filtering, index budget
aaditagrawal 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 * as FileSystem from "node:fs/promises"; | ||
| import * as Net from "node:net"; | ||
| import * as Path from "node:path"; | ||
| import * as Timers from "node:timers/promises"; | ||
|
|
||
| const defaultTcpHosts = ["127.0.0.1", "localhost", "::1"]; | ||
|
|
||
| async function fileExists(filePath) { | ||
| try { | ||
| await FileSystem.access(filePath); | ||
| return true; | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| function tcpPortIsReady({ host, port, connectTimeoutMs = 500 }) { | ||
| return new Promise((resolveReady) => { | ||
| const socket = Net.createConnection({ host, port }); | ||
| let settled = false; | ||
|
|
||
| const finish = (ready) => { | ||
| if (settled) { | ||
| return; | ||
| } | ||
|
|
||
| settled = true; | ||
| socket.removeAllListeners(); | ||
| socket.destroy(); | ||
| resolveReady(ready); | ||
| }; | ||
|
|
||
| socket.once("connect", () => { | ||
| finish(true); | ||
| }); | ||
| socket.once("timeout", () => { | ||
| finish(false); | ||
| }); | ||
| socket.once("error", () => { | ||
| finish(false); | ||
| }); | ||
| socket.setTimeout(connectTimeoutMs); | ||
| }); | ||
| } | ||
|
|
||
| async function resolvePendingResources({ baseDir, files, tcpPort, tcpHosts, connectTimeoutMs }) { | ||
| const pendingFiles = []; | ||
|
|
||
| for (const relativeFilePath of files) { | ||
| const ready = await fileExists(Path.resolve(baseDir, relativeFilePath)); | ||
| if (!ready) { | ||
| pendingFiles.push(relativeFilePath); | ||
| } | ||
| } | ||
|
|
||
| let tcpReady = false; | ||
| for (const host of tcpHosts) { | ||
| tcpReady = await tcpPortIsReady({ | ||
| host, | ||
| port: tcpPort, | ||
| connectTimeoutMs, | ||
| }); | ||
| if (tcpReady) { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| pendingFiles, | ||
| tcpReady, | ||
| }; | ||
| } | ||
|
|
||
| export async function waitForResources({ | ||
| baseDir, | ||
| files = [], | ||
| intervalMs = 100, | ||
| timeoutMs = 120_000, | ||
| tcpHost, | ||
| tcpPort, | ||
| connectTimeoutMs = 500, | ||
| }) { | ||
| if (!Number.isInteger(tcpPort) || tcpPort <= 0) { | ||
| throw new TypeError("waitForResources requires a positive integer tcpPort"); | ||
| } | ||
|
|
||
| const startedAt = Date.now(); | ||
| const tcpHosts = tcpHost ? [tcpHost] : defaultTcpHosts; | ||
|
|
||
| while (true) { | ||
| const { pendingFiles, tcpReady } = await resolvePendingResources({ | ||
| baseDir, | ||
| files, | ||
| tcpPort, | ||
| tcpHosts, | ||
| connectTimeoutMs, | ||
| }); | ||
|
|
||
| if (pendingFiles.length === 0 && tcpReady) { | ||
| return; | ||
| } | ||
|
|
||
| if (Date.now() - startedAt >= timeoutMs) { | ||
| const pendingResources = []; | ||
| if (!tcpReady) { | ||
| pendingResources.push(tcpHost ? `tcp:${tcpHost}:${tcpPort}` : `tcp:${tcpPort}`); | ||
| } | ||
| for (const filePath of pendingFiles) { | ||
| pendingResources.push(`file:${filePath}`); | ||
| } | ||
|
|
||
| throw new Error( | ||
| `Timed out waiting for desktop dev resources after ${timeoutMs}ms: ${pendingResources.join(", ")}`, | ||
| ); | ||
| } | ||
|
|
||
| await Timers.setTimeout(intervalMs); | ||
| } | ||
| } | ||
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.
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.
Validate full TCP port range (1–65535).
Line 83 currently allows values above
65535. That can fail later increateConnectionwith a low-level socket error instead of a clear argument error.🔧 Proposed fix
🤖 Prompt for AI Agents