mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-29 18:46:59 +00:00
test(photon): replace source-grep URL-routing tests with behavior tests
Follow-up to the URL markdown fix: extract the /send builder decision into sidecar/send-format.mjs and rewrite test_url_send_path.py to execute the real module under node (format+text in -> chosen builder out) instead of regex- grepping index.mjs source, which is a banned test pattern in this repo.
This commit is contained in:
parent
709dd3282f
commit
87fe75fde4
3 changed files with 105 additions and 40 deletions
|
|
@ -66,6 +66,7 @@ import http from "node:http";
|
|||
import crypto from "node:crypto";
|
||||
import { once } from "node:events";
|
||||
import { patchSpectrumTs } from "./patch-spectrum-mixed-attachments.mjs";
|
||||
import { chooseSendFormat } from "./send-format.mjs";
|
||||
|
||||
const projectId = process.env.PHOTON_PROJECT_ID;
|
||||
const projectSecret = process.env.PHOTON_PROJECT_SECRET;
|
||||
|
|
@ -894,10 +895,10 @@ const server = http.createServer(async (req, res) => {
|
|||
// iMessage API, which can 500 on messages containing raw URLs.
|
||||
// Plain-text URLs are auto-linked by iMessage, so route markdown
|
||||
// messages that contain URLs through spectrumText while preserving
|
||||
// spectrumMarkdown for URL-free markdown.
|
||||
const hasUrl = /https?:\/\/[^\s)'"<>]+/i.test(text);
|
||||
// spectrumMarkdown for URL-free markdown. The decision lives in
|
||||
// send-format.mjs so tests can exercise it directly.
|
||||
const builder =
|
||||
format === "markdown" && !hasUrl
|
||||
chooseSendFormat(format, text) === "markdown"
|
||||
? spectrumMarkdown(text)
|
||||
: spectrumText(text);
|
||||
const result = await space.send(builder);
|
||||
|
|
|
|||
27
plugins/platforms/photon/sidecar/send-format.mjs
Normal file
27
plugins/platforms/photon/sidecar/send-format.mjs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// Outbound /send builder selection for the Photon sidecar.
|
||||
//
|
||||
// spectrumMarkdown() enables data detection (enableDataDetection) in the
|
||||
// underlying iMessage API, which can 500 on messages containing raw URLs.
|
||||
// Plain-text URLs are auto-linked by iMessage anyway, so markdown messages
|
||||
// that contain a URL are routed through the text builder, while URL-free
|
||||
// markdown keeps native markdown rendering.
|
||||
//
|
||||
// This lives in its own module (rather than inline in index.mjs) so tests can
|
||||
// execute the real decision logic under node instead of grepping source —
|
||||
// see tests/plugins/platforms/photon/test_url_send_path.py.
|
||||
|
||||
const URL_RE = /https?:\/\/[^\s)'"<>]+/i;
|
||||
|
||||
/**
|
||||
* Decide which spectrum-ts builder the /send handler should use.
|
||||
*
|
||||
* @param {string} format "markdown" | "text" (already validated by /send)
|
||||
* @param {string} text the outbound message body
|
||||
* @returns {"markdown"|"text"}
|
||||
*/
|
||||
export function chooseSendFormat(format, text) {
|
||||
if (format === "markdown" && !URL_RE.test(String(text))) {
|
||||
return "markdown";
|
||||
}
|
||||
return "text";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue