Skip to content

Commit f51708b

Browse files
committed
added measure costs
1 parent 87ad1cd commit f51708b

11 files changed

Lines changed: 524 additions & 25 deletions

.github/workflows/daily-testnet-ts.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,14 @@ jobs:
7171
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
7272
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
7373
STATUS: ${{ job.status }}
74+
BRANCH: ${{ github.ref_name }}
75+
LOG_PATH: daily-testnet-ts.log
76+
SUMMARY_PATH: daily-testnet-ts-ai-summary.md
77+
REPORT_TITLE: Daily Testnet TS
78+
REPORT_MODE: testnet
79+
REPORT_ETH_LABEL: hoodi-reth
7480
run: |
75-
SUMMARY_FILE="daily-testnet-ts-ai-summary.md"
76-
if [ -f "$SUMMARY_FILE" ]; then
77-
SUMMARY=$(cat "$SUMMARY_FILE")
78-
else
79-
SUMMARY="AI summary unavailable."
80-
fi
81-
MESSAGE=$(printf 'Daily Testnet TS\nStatus: %s\nBranch: %s\nRun: %s\n\n%s' \
82-
"${STATUS}" \
83-
"${{ github.ref_name }}" \
84-
"${RUN_URL}" \
85-
"${SUMMARY}")
81+
MESSAGE=$(node ./script/format-telegram-test-report.mjs)
8682
curl -sS -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
8783
-d chat_id="${TELEGRAM_CHAT_ID}" \
8884
--data-urlencode "text=${MESSAGE}"
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Manual VFT Debug
2+
run-name: Manual VFT Debug (${{ inputs.test_file }}, ${{ inputs.injected_validator_mode }})
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
test_file:
8+
description: VFT test file to run
9+
required: true
10+
type: choice
11+
default: test/vft/vft.test.ts
12+
options:
13+
- test/vft/vft.test.ts
14+
- test/vft/vft.load.test.ts
15+
injected_validator_mode:
16+
description: Injected transaction validator routing mode
17+
required: true
18+
type: choice
19+
default: default
20+
options:
21+
- default
22+
- slot
23+
24+
concurrency:
25+
group: manual-vft-debug-${{ github.ref_name }}
26+
cancel-in-progress: false
27+
28+
jobs:
29+
manual-vft-debug:
30+
runs-on: ubuntu-latest
31+
timeout-minutes: 90
32+
33+
steps:
34+
- name: Checkout repository
35+
uses: actions/checkout@v4
36+
37+
- name: Set up pnpm
38+
uses: pnpm/action-setup@v4
39+
40+
- name: Set up Node.js
41+
uses: actions/setup-node@v4
42+
with:
43+
node-version: 22
44+
cache: pnpm
45+
46+
- name: Install JavaScript dependencies
47+
run: pnpm install --frozen-lockfile
48+
49+
- name: Run manual VFT debug suite
50+
env:
51+
TESTNET_PRIVATE_KEY: ${{ secrets.TESTNET_PRIVATE_KEY }}
52+
TESTNET_SENDER: ${{ secrets.TESTNET_SENDER }}
53+
TESTNET_TOKEN_ID: ${{ vars.TESTNET_TOKEN_ID }}
54+
VFT_DEBUG_TEST_FILE: ${{ inputs.test_file }}
55+
VFT_INJECTED_VALIDATOR_MODE: ${{ inputs.injected_validator_mode }}
56+
run: |
57+
set -euo pipefail
58+
./script/run-testnet-vft-debug-ts.sh 2>&1 | tee manual-vft-debug.log
59+
60+
- name: Upload manual VFT debug log
61+
if: always()
62+
uses: actions/upload-artifact@v4
63+
with:
64+
name: manual-vft-debug-log
65+
path: manual-vft-debug.log
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Weekly Testnet Load
2+
run-name: Weekly Testnet Load (${{ github.ref_name }})
3+
4+
on:
5+
schedule:
6+
- cron: "0 9 * * 1"
7+
workflow_dispatch:
8+
9+
concurrency:
10+
group: weekly-testnet-load
11+
cancel-in-progress: false
12+
13+
jobs:
14+
weekly-testnet-load:
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 90
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Set up pnpm
23+
uses: pnpm/action-setup@v4
24+
25+
- name: Set up Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: 22
29+
cache: pnpm
30+
31+
- name: Install JavaScript dependencies
32+
run: pnpm install --frozen-lockfile
33+
34+
- name: Run weekly testnet load suite
35+
env:
36+
TESTNET_PRIVATE_KEY: ${{ secrets.TESTNET_PRIVATE_KEY }}
37+
TESTNET_SENDER: ${{ secrets.TESTNET_SENDER }}
38+
TESTNET_TOKEN_ID: ${{ vars.TESTNET_TOKEN_ID }}
39+
VFT_INJECTED_VALIDATOR_MODE: default
40+
run: |
41+
set -euo pipefail
42+
./script/run-testnet-weekly-load-ts.sh 2>&1 | tee weekly-testnet-load.log
43+
44+
- name: Upload weekly testnet load log
45+
if: always()
46+
uses: actions/upload-artifact@v4
47+
with:
48+
name: weekly-testnet-load-log
49+
path: weekly-testnet-load.log

script/analyze-testnet-ts-run.mjs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ const LOG_PATH = process.env.LOG_PATH || "daily-testnet-ts.log";
66
const OUTPUT_PATH =
77
process.env.OUTPUT_PATH || "daily-testnet-ts-ai-summary.md";
88

9-
if (!OPENAI_API_KEY) {
10-
throw new Error("OPENAI_API_KEY is required");
11-
}
12-
139
function readText(path, maxChars) {
1410
if (!existsSync(path)) {
1511
return `File not found: ${path}`;
@@ -43,6 +39,22 @@ function extractResponseText(data) {
4339
return parts.join("\n").trim();
4440
}
4541

42+
function writeFallbackSummary(reason) {
43+
const summary = [
44+
"Summary: AI analysis skipped; test status is available in the GitHub Actions log.",
45+
`Risk: ${reason}`,
46+
"Next: Check the uploaded test log artifact for details if the workflow failed.",
47+
].join("\n");
48+
49+
writeFileSync(OUTPUT_PATH, `${summary}\n`);
50+
console.log(summary);
51+
}
52+
53+
if (!OPENAI_API_KEY) {
54+
writeFallbackSummary("OPENAI_API_KEY is not configured.");
55+
process.exit(0);
56+
}
57+
4658
const agents = readText("AGENTS.md", 12_000);
4759
const workflow = readText(".github/workflows/daily-testnet-ts.yml", 8_000);
4860
const runner = readText("script/run-testnet-daily-ts.sh", 6_000);
@@ -102,14 +114,16 @@ const response = await fetch("https://api.openai.com/v1/responses", {
102114

103115
if (!response.ok) {
104116
const body = await response.text();
105-
throw new Error(`OpenAI API error ${response.status}: ${body}`);
117+
writeFallbackSummary(`OpenAI API returned ${response.status}; ${body.slice(0, 300)}`);
118+
process.exit(0);
106119
}
107120

108121
const data = await response.json();
109122
const summary = extractResponseText(data);
110123

111124
if (!summary) {
112-
throw new Error("OpenAI API returned an empty analysis");
125+
writeFallbackSummary("OpenAI API returned an empty analysis.");
126+
process.exit(0);
113127
}
114128

115129
writeFileSync(OUTPUT_PATH, `${summary}\n`);
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { existsSync, readFileSync } from "node:fs";
2+
3+
const logPath = process.env.LOG_PATH || "daily-testnet-ts.log";
4+
const summaryPath =
5+
process.env.SUMMARY_PATH || "daily-testnet-ts-ai-summary.md";
6+
const status = process.env.STATUS || "unknown";
7+
const branch = process.env.BRANCH || "unknown";
8+
const runUrl = process.env.RUN_URL || "unknown";
9+
const title = process.env.REPORT_TITLE || "Daily Testnet TS";
10+
const mode = process.env.REPORT_MODE || "testnet";
11+
const ethLabel = process.env.REPORT_ETH_LABEL || "hoodi-reth";
12+
13+
function readIfExists(path) {
14+
return existsSync(path) ? readFileSync(path, "utf8") : "";
15+
}
16+
17+
function extractTests(log) {
18+
const passed = log.match(/Tests\s+(\d+)\s+passed\s+\((\d+)\)/);
19+
if (passed) {
20+
return `${passed[1]}/${passed[2]}`;
21+
}
22+
23+
const failed = log.match(/Tests\s+(\d+)\s+failed\s+\|\s+(\d+)\s+passed\s+\((\d+)\)/);
24+
if (failed) {
25+
return `${failed[2]}/${failed[3]} passed, ${failed[1]} failed`;
26+
}
27+
28+
return "unknown";
29+
}
30+
31+
function extractDuration(log) {
32+
const match = log.match(/Duration\s+([0-9.]+)(ms|s|m)/);
33+
if (!match) {
34+
return "unknown";
35+
}
36+
37+
const value = Number(match[1]);
38+
const unit = match[2];
39+
if (!Number.isFinite(value)) {
40+
return `${match[1]}${unit}`;
41+
}
42+
43+
const seconds =
44+
unit === "ms" ? value / 1_000 : unit === "m" ? value * 60 : value;
45+
const minutes = Math.floor(seconds / 60);
46+
const remainingSeconds = Math.round(seconds % 60);
47+
48+
if (minutes === 0) {
49+
return `${remainingSeconds}s`;
50+
}
51+
52+
return `${minutes}m ${remainingSeconds.toString().padStart(2, "0")}s`;
53+
}
54+
55+
function extractCosts(log) {
56+
const match = log.match(/TEST_COSTS delta eth=([^\s]+) wvara=([^\s]+)/);
57+
if (!match) {
58+
return {
59+
eth: "unknown",
60+
wvara: "unknown",
61+
};
62+
}
63+
64+
return {
65+
eth: match[1],
66+
wvara: match[2],
67+
};
68+
}
69+
70+
const log = readIfExists(logPath);
71+
const summary = readIfExists(summaryPath).trim() || "AI summary unavailable.";
72+
const tests = extractTests(log);
73+
const duration = extractDuration(log);
74+
const costs = extractCosts(log);
75+
76+
const message = [
77+
title,
78+
`Status: ${status}`,
79+
`Tests: ${tests}`,
80+
`Duration: ${duration}`,
81+
`Cost ETH: ${costs.eth}`,
82+
`Cost WVARA: ${costs.wvara}`,
83+
`Mode: ${mode}`,
84+
`ETH: ${ethLabel}`,
85+
`Branch: ${branch}`,
86+
`Run: ${runUrl}`,
87+
"",
88+
summary,
89+
].join("\n");
90+
91+
console.log(message);

0 commit comments

Comments
 (0)