Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions test/e2e/live/common-egress-agent-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,19 +452,18 @@ export function reduceOpenClawToolEvidence(
const expectedMs = Date.parse(expected);
if (!Number.isFinite(expectedMs)) return false;
const expectedDate = new Date(expectedMs).toISOString().slice(0, 10);
if (
text.includes(expectedDate) ||
text.includes(expectedDate.replace(/-/gu, "")) ||
text.includes(expected)
) {
return true;
if (/^\d{4}-\d{2}-\d{2}$/u.test(expected)) {
const dateTokenMatches = (candidate: string): boolean =>
new RegExp(`(?:^|[^0-9])${candidate}(?![0-9]|T|\\s+\\d{2}:)`, "u").test(text);
return dateTokenMatches(expectedDate) || dateTokenMatches(expectedDate.replace(/-/gu, ""));
}
if (text.includes(expected)) return true;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
for (const match of text.matchAll(/(?:^|\D)(\d{10}|\d{13})(?!\d)/gu)) {
const raw = match[1];
if (!raw) continue;
const epochMs = Number(raw) * (raw.length === 10 ? 1_000 : 1);
if (!Number.isFinite(epochMs)) continue;
if (new Date(epochMs).toISOString().slice(0, 10) === expectedDate) return true;
if (epochMs === expectedMs) return true;
}
return false;
};
Expand Down
21 changes: 17 additions & 4 deletions test/e2e/live/openclaw-agent-assertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,26 @@ export async function runOpenClawAgentAssertion(
}

export const PERSONAL_STOCK_PROMPT = `Find the latest available NVIDIA (NVDA) stock price.
Choose a small, machine-readable public HTTPS source yourself and use web_fetch as the only target tool.
Choose a small, machine-readable public HTTPS source whose response contains one NVDA price and its market or update timestamp.
Use web_fetch as the only target tool.
If progressive tool disclosure is active, you may use tool_search, tool_describe, and tool_call only to discover and invoke web_fetch.
Do not invoke any other target tool. Do not use web_search, Brave Search, or Tavily Search.
Set web_fetch maxChars to no more than 8000.
Only after web_fetch returns a numeric NVDA price with its source date or timestamp, reply with one JSON object and no Markdown.
Set status to NVDA_PERSONAL_AGENT_OK, symbol to NVDA, price to a JSON number, source_url to the exact HTTPS URL passed to web_fetch, and as_of to the quote's own market or update timestamp converted to ISO 8601.
For a Unix-epoch quote field such as regularMarketTime, convert that field to ISO 8601. Never use the current clock, fetch time, or an unrelated date for as_of.`;
If a web_fetch result omits the quote timestamp, do not use its price or infer a timestamp.
Fetch a different machine-readable source instead.
Reply only after one web_fetch result contains NVDA, a numeric price, and its market or update timestamp.
Use the price and as_of values from that result. Set source_url to the exact URL for its paired web_fetch call.
If no result contains all three values, do not return success.
Reply with one JSON object and no Markdown.
Return these fields:
- status: NVDA_PERSONAL_AGENT_OK
- symbol: NVDA
- price: the quote price as a JSON number
- source_url: the exact URL for the paired web_fetch call
- as_of: the quote's own market or update timestamp
Copy an extended ISO 8601 source date or timestamp exactly. Convert a compact YYYYMMDD source date to YYYY-MM-DD.
For a Unix-epoch field such as regularMarketTime, convert that field exactly to ISO 8601.
Never use the current clock, fetch time, or an unrelated date for as_of.`;

export async function runPersonalStockAgentAssertion(
host: HostCliClient,
Expand Down
73 changes: 73 additions & 0 deletions test/e2e/support/common-egress-agent-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { join } from "node:path";

import { describe, expect, it, vi } from "vitest";

import { PERSONAL_STOCK_PROMPT } from "../live/openclaw-agent-assertion.ts";
import {
agentReplyContainsToken,
assessPersonalStockToolEvidence,
Expand Down Expand Up @@ -281,6 +282,18 @@ async function expectAggregateStockFailure(
}

describe("common-egress agent parsing and classification helpers", () => {
it("requires one stock result to contain the price and quote timestamp (#10330)", () => {
expect(PERSONAL_STOCK_PROMPT).toContain(
"If a web_fetch result omits the quote timestamp, do not use its price or infer a timestamp.",
);
expect(PERSONAL_STOCK_PROMPT).toContain(
"Use the price and as_of values from that result. Set source_url to the exact URL for its paired web_fetch call.",
);
expect(PERSONAL_STOCK_PROMPT).toContain(
"If no result contains all three values, do not return success.",
);
});

it("OpenClaw JSON parser accepts framed agent payloads", () => {
expect(
parseOpenClawAgentText(
Expand Down Expand Up @@ -357,6 +370,36 @@ describe("common-egress agent parsing and classification helpers", () => {
);
});

it.each([
{ name: "an ISO date", sourceTime: "2026-08-17", asOf: "2026-08-17" },
{ name: "a compact date", sourceTime: "20260817", asOf: "2026-08-17" },
{ name: "an exact ISO timestamp", sourceTime: STOCK_REPLY.as_of, asOf: STOCK_REPLY.as_of },
{ name: "a Unix timestamp in seconds", sourceTime: "1786982340", asOf: STOCK_REPLY.as_of },
{
name: "a Unix timestamp in milliseconds",
sourceTime: "1786982340000",
asOf: STOCK_REPLY.as_of,
},
])(
"accepts $name as quote-time evidence from one paired stock result (#10330)",
({ asOf, sourceTime }) => {
const evidence = reduceOpenClawToolEvidence(
stockSessionJsonLines({
payload: stockPayload({
text: `{"symbol":"NVDA","regularMarketPrice":192.38,"quoteTime":"${sourceTime}"}`,
}),
}),
stockTrajectory(),
{ ...STOCK_REPLY, as_of: asOf },
);

expect(assessPersonalStockToolEvidence(evidence)).toMatchObject({
matches: true,
qualifyingWebFetchResults: 1,
});
},
);

it("executes the generated reducer script against OpenClaw JSONL artifacts", () => {
const directory = mkdtempSync(join(tmpdir(), "nemoclaw-openclaw-reducer-"));
try {
Expand Down Expand Up @@ -938,6 +981,36 @@ describe("common-egress agent parsing and classification helpers", () => {
trajectory: stockTrajectory(),
expected: STOCK_REPLY,
},
{
name: "price paired with an unrelated source date (#10330)",
session: stockSessionJsonLines({
payload: stockPayload({
text: '{"symbol":"NVDA","regularMarketPrice":192.38,"date":"2026-08-16"}',
}),
}),
trajectory: stockTrajectory(),
expected: STOCK_REPLY,
},
{
name: "price paired with a shifted same-day timestamp (#10330)",
session: stockSessionJsonLines({
payload: stockPayload({
text: '{"symbol":"NVDA","regularMarketPrice":192.38,"quoteTime":"2026-08-17T20:00:00Z"}',
}),
}),
trajectory: stockTrajectory(),
expected: STOCK_REPLY,
},
{
name: "date-only reply paired with a source timestamp (#10330)",
session: stockSessionJsonLines({
payload: stockPayload({
text: '{"symbol":"NVDA","regularMarketPrice":192.38,"quoteTime":"2026-08-17T20:00:00Z"}',
}),
}),
trajectory: stockTrajectory(),
expected: { ...STOCK_REPLY, as_of: "2026-08-17" },
},
])("rejects $name", ({ expected, session, trajectory }) => {
const evidence = reduceOpenClawToolEvidence(session, trajectory, expected);

Expand Down
Loading