mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-27 23:25:22 -04:00
5d23495eb2
* Fix #4507: only block model launch on real port collisions Quick-run hardcoded port 8000 and never called _nextAvailablePort(), so every launch collided. Both pre-launch guards (serve panel + quick-run) were count-based and fired regardless of port. - quick-run now auto-assigns a free port (8080 for llama.cpp) - both guards parse the new port and only prompt on a real overlap, stopping only the colliding serve - dialog reports the actual port instead of a hardcoded 8000 * refactor(cookbook): share _taskPort for port parsing; auto-assign llama.cpp port Addresses review on #4760: - _taskPort regex now matches --port= as well as --port (space) - _nextAvailablePort and both launch guards reuse _taskPort instead of inline regex - quick-run llama.cpp no longer pins 8080, so two can run concurrently * fix(cookbook): _taskPort also parses -p; add port-parsing tests Addresses review on #4760: - _taskPort now matches -p <n> too, so it's the complete single reader (was missing the short flag that other readers already handle) - add tests/test_cookbook_port_parsing_js.py covering the port forms, shared-reader reuse, and llama.cpp auto-assign * test(cookbook): extract pure port helpers and test behavior Addresses review on #4760: the prior tests only asserted source strings. - extract portOf() and nextFreePort() into static/js/cookbookPorts.js - cookbookRunning.js imports them; _taskPort and _nextAvailablePort delegate - tests run the helpers via node and assert real behavior: all port forms (--port, --port=, -p, -p=), next-free-port skipping taken ports, and the same-port-clash / different-port-coexist outcome --------- Co-authored-by: samy <samy@odysseus.boukouro.com>
20 lines
779 B
JavaScript
20 lines
779 B
JavaScript
// Pure port helpers extracted so they're unit-testable without the
|
|
// browser-bound rest of cookbookRunning.js (issue #4507 follow-up).
|
|
|
|
// Read the port out of a serve launch command. Handles --port 8000,
|
|
// --port=8000, -p 8000, and -p=8000. Returns '' when none is present.
|
|
export function portOf(cmd) {
|
|
const s = cmd || '';
|
|
const m = s.match(/--port[=\s]+(\d+)/) || s.match(/(?:^|\s)-p[=\s]+(\d+)/);
|
|
return m ? m[1] : '';
|
|
}
|
|
|
|
// Lowest free port >= start that isn't in usedPorts (array or Set of
|
|
// numbers/strings). Returns a string to match the serve command format.
|
|
export function nextFreePort(usedPorts, start = 8000) {
|
|
const used = new Set([...usedPorts].map(p => parseInt(p, 10)));
|
|
let port = start;
|
|
while (used.has(port)) port++;
|
|
return String(port);
|
|
}
|