Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 4 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: ci

on:
push:
branches: [main]
pull_request:

permissions:
Expand All @@ -18,7 +19,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-15-intel]
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v7
Expand All @@ -33,10 +34,11 @@ jobs:
run: go test -race ./internal/usage ./internal/store ./internal/server
- name: Native macOS install, restart and uninstall
if: runner.os == 'macOS'
run: for attempt in 1 2 3; do bash scripts/test-macos.sh; done
run: bash scripts/test-macos.sh

cross-build:
name: cross-build
if: github.event_name == 'push'
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
Expand All @@ -46,11 +48,6 @@ jobs:
go-version: "1.26.8"
cache: true
- run: bash ./scripts/build.sh
- uses: actions/upload-artifact@v7
with:
name: codex-usage-binaries
path: dist/
if-no-files-found: error

dashboard:
name: dashboard
Expand Down
2 changes: 1 addition & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ By default, `npm test` builds and launches a real Go binary in a temporary direc

Regenerate README animations, videos, and screenshots with `npm run capture:media`, and the 30-second promo with `npm run capture:promo`; see [media notes](docs/media/README.md) for dependencies, scenarios, and recording checks.

Current [CI](https://github.com/zJay26/codex-usage/actions/workflows/ci.yml) covers Go tests and vet on Windows, Linux, macOS Apple Silicon / Intel, Linux concurrency checks, six-target cross-builds, and Dashboard tests. Each macOS architecture also runs three install/uninstall/reinstall cycles. Release publication requires the native macOS checks to pass.
Current [CI](https://github.com/zJay26/codex-usage/actions/workflows/ci.yml) covers Go tests and vet on Windows, Linux, and macOS Apple Silicon, Linux concurrency checks, Dashboard tests, and one native macOS install/uninstall/reinstall cycle; merges to main also run six-target cross-builds. Release publication additionally repeats the native install checks three times on both macOS Apple Silicon and Intel.

See [the v2.6 technical and verification notes](docs/accounting-v2.6.md) for accounting regressions, task trees, remote time-zone charts, and performance evidence. [ACCEPTANCE.md](ACCEPTANCE.md) archives earlier releases. Read [CONTRIBUTING.md](CONTRIBUTING.md) before opening an issue and [SECURITY.md](SECURITY.md) for private vulnerability reporting.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ npm test

README 动图、视频和截图可通过 `npm run capture:media` 重新生成,30 秒宣传片可通过 `npm run capture:promo` 重新生成;依赖、演示场景与录制检查见 [媒体说明](docs/media/README.md)。

当前 [CI](https://github.com/zJay26/codex-usage/actions/workflows/ci.yml) 覆盖 Windows、Linux、macOS Apple Silicon / Intel 的 Go 测试与 vet、Linux 并发检查、六目标交叉构建及 Dashboard 测试;两个 macOS 架构还各执行三轮安装、卸载和重装。Release 发布也要求原生 macOS 检查通过。
当前 [CI](https://github.com/zJay26/codex-usage/actions/workflows/ci.yml) 覆盖 Windows、Linux、macOS Apple Silicon 的 Go 测试与 vet、Linux 并发检查、Dashboard 测试,以及 macOS 上的一轮安装、卸载和重装;合并到 main 后还会做六目标交叉构建。Release 发布前还会在 macOS Apple Silicon / Intel 上各重复三轮原生安装检查。

v2.6 的计量回归、任务树、远程时区图表与性能证据见 [技术与验证说明](docs/accounting-v2.6.md);旧版本验收记录归档于 [ACCEPTANCE.md](ACCEPTANCE.md)。问题反馈前请阅读 [CONTRIBUTING.md](CONTRIBUTING.md);涉及本机数据或路径的安全问题请按 [SECURITY.md](SECURITY.md) 私密报告。

Expand Down
107 changes: 5 additions & 102 deletions tests/dashboard.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ test.beforeAll(async () => {
const port = await findFreePort();
codexHomeDir = await mkdtemp(path.join(tmpdir(), "codex-usage-codex-home-"));
const codexHome = codexHomeDir;
// The hourly assertions target the current hour; if the suite would straddle
// an hour boundary, wait it out instead of failing intermittently.
const clock = new Date();
const msToNextHour = 3_600_000 - (clock.getMinutes() * 60_000 + clock.getSeconds() * 1_000 + clock.getMilliseconds());
if (msToNextHour < 150_000) await delay(msToNextHour + 1_000);
const now = new Date();
const currentHour = new Date(now);
currentHour.setMinutes(0, 0, 0);
Expand Down Expand Up @@ -271,108 +276,6 @@ test("overview is calm, local-only, and exposes honest cost coverage", async ({
expect(consoleErrors).toEqual([]);
});

test("hourly usage inspects the selected point and navigates across local days", async ({ page }) => {
const hourlyRequests = [];
const hourlyCostRequests = [];
page.on("request", (request) => {
const url = new URL(request.url());
if (url.pathname === "/api/v1/timeseries" && url.searchParams.get("bucket") === "hour") hourlyRequests.push(url);
if (url.pathname === "/api/v1/cost-estimate" && url.searchParams.has("since") && url.searchParams.has("until")
&& Date.parse(url.searchParams.get("until")) - Date.parse(url.searchParams.get("since")) === 60 * 60 * 1000) hourlyCostRequests.push(url);
});
await page.goto(dashboardURL, { waitUntil: "networkidle" });
const trend = page.locator("#usageTrendPanel");
await trend.getByRole("tab", { name: "每小时" }).click();
await expect(page.getByRole("heading", { name: "每小时Token用量" })).toBeVisible();
await expect(trend.getByText("最近 60 分钟", { exact: true })).toHaveCount(0);
await expect(trend.getByText("上一小时", { exact: true })).toHaveCount(0);
await expect(page.locator("#hourPointInspector")).toHaveCount(0);
await expect(page.locator("#hourlyDatePicker")).toHaveValue(/^\d{4}-\d{2}-\d{2}$/);
await expect(page.locator("#hourlyDateYear")).not.toHaveText("—");
await expect(page.locator("#hourlyDateLabel")).not.toHaveText("—");
const dateType = await page.locator("#hourlyDateLabel").evaluate((node) => ({
year: Number.parseFloat(getComputedStyle(document.querySelector("#hourlyDateYear")).fontSize),
date: Number.parseFloat(getComputedStyle(node).fontSize)
}));
expect(dateType.year).toBeGreaterThanOrEqual(11);
expect(dateType.date).toBeGreaterThanOrEqual(16);
await expect(page.locator("#hourlyTotal")).toHaveText("60");
await expect(page.locator("#hourlyCost")).toHaveText(/^\$/);
await expect(page.locator("#hourlyModels").getByText("gpt-5.4", { exact: true })).toBeVisible();
await expect(page.locator("#hourlyCostCoverage")).toHaveText("100.0%");
await expect(page.locator("#hourlyCostNote")).toContainText("Fast");
const summaryType = await page.evaluate(() => ({
window: Number.parseFloat(getComputedStyle(document.querySelector("#hourlyWindowLabel")).fontSize),
ledger: Number.parseFloat(getComputedStyle(document.querySelector("#hourlyInput")).fontSize)
}));
expect(summaryType.window).toBeGreaterThanOrEqual(15);
expect(summaryType.ledger).toBeGreaterThanOrEqual(16);
await expect(page.locator("#hourlyLine .hour-line-path")).toHaveCount(1);
const hourPoints = page.locator("#hourlyPoints .hour-point");
const expectedHours = await page.evaluate(() => new Date().getHours() || 24);
await expect(hourPoints).toHaveCount(expectedHours);
await expect(hourPoints.last()).toHaveClass(/selected/);
await hourPoints.first().focus();
await expect(hourPoints.first()).toHaveAttribute("aria-pressed", "true");
if (expectedHours > 1) {
await expect(page.locator("#hourlyTotal")).toHaveText("0");
await expect(page.locator("#hourlyCost")).toHaveText("$0.00");
await expect(page.locator("#hourlyModels")).toContainText("没有模型用量");
}
await hourPoints.first().press("End");
await expect(hourPoints.last()).toHaveAttribute("aria-pressed", "true");
await expect(page.locator("#hourlyTotal")).toHaveText("60");
const alignment = await page.evaluate(() => {
const svg = document.querySelector("#hourlyLine");
const polyline = svg.querySelector(".hour-line-path");
const svgRect = svg.getBoundingClientRect();
const coordinates = polyline.getAttribute("points").trim().split(/\s+/).map((pair) => pair.split(",").map(Number));
return [...document.querySelectorAll("#hourlyPoints .hour-point")].map((button, index) => {
const rect = button.getBoundingClientRect();
const [x, y] = coordinates[index];
return {
x: Math.abs(rect.left + rect.width / 2 - (svgRect.left + x / 1000 * svgRect.width)),
y: Math.abs(rect.top + rect.height / 2 - (svgRect.top + y / 180 * svgRect.height))
};
});
});
expect(Math.max(...alignment.map(({ x }) => x))).toBeLessThan(0.5);
expect(Math.max(...alignment.map(({ y }) => y))).toBeLessThan(0.5);
await expect(page.locator("#hourlyWindowLabel")).not.toHaveText("—");

const initialDate = await page.locator("#hourlyDatePicker").inputValue();
await page.locator("#previousHourDay").click();
const previousDate = await page.locator("#hourlyDatePicker").inputValue();
expect(previousDate).toBe(await page.evaluate((value) => {
const [year, month, day] = value.split("-").map(Number);
const date = new Date(year, month - 1, day);
date.setDate(date.getDate() - 1);
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
}, initialDate));
await expect(hourPoints).toHaveCount(24);
await expect(hourPoints.last()).toHaveClass(/selected/);
await expect(page.locator("#currentHourDay")).toBeEnabled();
const arbitraryDate = await page.evaluate((value) => {
const [year, month, day] = value.split("-").map(Number);
const date = new Date(year, month - 1, day);
date.setDate(date.getDate() - 8);
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
}, initialDate);
await page.locator("#hourlyDatePicker").fill(arbitraryDate);
await page.locator("#hourlyDatePicker").dispatchEvent("change");
await expect(page.locator("#hourlyDatePicker")).toHaveValue(arbitraryDate);
await expect(page.locator("#trendHourlyPane")).not.toHaveAttribute("aria-busy", "true");
await expect(hourPoints).toHaveCount(24);
await page.locator("#currentHourDay").click();
await expect(page.locator("#hourlyDatePicker")).toHaveValue(await page.evaluate(() => {
const now = new Date();
return `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")}`;
}));
await expect(page.locator("#currentHourDay")).toBeDisabled();
expect(hourlyRequests.some((url) => url.searchParams.get("date") === arbitraryDate && url.searchParams.get("complete_hours") === "1")).toBeTruthy();
expect(hourlyCostRequests.length).toBeGreaterThan(0);
});

test("view switching exposes the target panel immediately", async ({ page }) => {
await page.goto(dashboardURL, { waitUntil: "networkidle" });
const elapsed = await page.evaluate(async () => {
Expand Down
Loading