Compare commits

...

2 Commits

Author SHA1 Message Date
jayavibhavnk
6b1ae10f50 fix(test): add missing useFileDropZone and FileDropOverlay to editor mock
create-issue.tsx imports useFileDropZone and FileDropOverlay from
../editor, but the vi.mock("../editor") in create-issue.test.tsx did
not include them. Vitest aborts with "No useFileDropZone export is
defined on the mock" before the test even runs.

Added both missing exports to the mock — FileDropOverlay renders null
and useFileDropZone returns a stable stub — matching the pattern used
in issue-detail.test.tsx.
2026-04-12 22:44:40 +08:00
jayavibhavnk
67212b0bef fix(server): fix ListRuntimeUsage to filter by date range instead of row count
GetRuntimeUsage accepted a ?days=N query parameter intended to return N
days of history, but the underlying ListRuntimeUsage query used it as a
raw LIMIT on rows. When a runtime uses multiple models (e.g. claude-opus
and claude-sonnet), each day produces multiple rows, so LIMIT 90 would
only return ~30 days of data instead of 90, silently truncating history.

Fix: replace the LIMIT clause with AND date >= $2 in the SQL query,
update ListRuntimeUsageParams to hold a Since pgtype.Date instead of a
Limit int32, and compute the date cutoff in the handler using
time.Now().AddDate(0, 0, -days). The generated Go code and the handler
are updated consistently.

Closes #731

Made-with: Cursor
2026-04-12 22:42:56 +08:00
5 changed files with 20 additions and 13 deletions

View File

@@ -94,7 +94,10 @@ vi.mock("../../editor", () => ({
ReadonlyContent: ({ content }: { content: string }) => (
<div data-testid="readonly-content">{content}</div>
),
ContentEditor: forwardRef(({ defaultValue, onUpdate, placeholder }: any, ref: any) => {
ContentEditor: forwardRef(function MockContentEditor(
{ defaultValue, onUpdate, placeholder }: any,
ref: any,
) {
const valueRef = useRef(defaultValue || "");
const [value, setValue] = useState(defaultValue || "");
useImperativeHandle(ref, () => ({
@@ -116,7 +119,10 @@ vi.mock("../../editor", () => ({
/>
);
}),
TitleEditor: forwardRef(({ defaultValue, placeholder, onBlur, onChange }: any, ref: any) => {
TitleEditor: forwardRef(function MockTitleEditor(
{ defaultValue, placeholder, onBlur, onChange }: any,
ref: any,
) {
const valueRef = useRef(defaultValue || "");
const [value, setValue] = useState(defaultValue || "");
useImperativeHandle(ref, () => ({

View File

@@ -228,7 +228,7 @@ export function SearchCommand() {
setOpen(false);
push(href);
},
[push],
[push, setOpen],
);
return (

View File

@@ -135,16 +135,17 @@ func (h *Handler) GetRuntimeUsage(w http.ResponseWriter, r *http.Request) {
return
}
limit := int32(90)
if l := r.URL.Query().Get("days"); l != "" {
if parsed, err := strconv.Atoi(l); err == nil && parsed > 0 && parsed <= 365 {
limit = int32(parsed)
days := 90
if d := r.URL.Query().Get("days"); d != "" {
if parsed, err := strconv.Atoi(d); err == nil && parsed > 0 && parsed <= 365 {
days = parsed
}
}
since := pgtype.Date{Time: time.Now().AddDate(0, 0, -days), Valid: true}
rows, err := h.Queries.ListRuntimeUsage(r.Context(), db.ListRuntimeUsageParams{
RuntimeID: parseUUID(runtimeID),
Limit: limit,
Since: since,
})
if err != nil {
writeError(w, http.StatusInternalServerError, "failed to list usage")

View File

@@ -95,17 +95,17 @@ func (q *Queries) GetRuntimeUsageSummary(ctx context.Context, runtimeID pgtype.U
const listRuntimeUsage = `-- name: ListRuntimeUsage :many
SELECT id, runtime_id, date, provider, model, input_tokens, output_tokens, cache_read_tokens, cache_write_tokens, created_at, updated_at FROM runtime_usage
WHERE runtime_id = $1
AND date >= $2
ORDER BY date DESC
LIMIT $2
`
type ListRuntimeUsageParams struct {
RuntimeID pgtype.UUID `json:"runtime_id"`
Limit int32 `json:"limit"`
Since pgtype.Date `json:"since"`
}
func (q *Queries) ListRuntimeUsage(ctx context.Context, arg ListRuntimeUsageParams) ([]RuntimeUsage, error) {
rows, err := q.db.Query(ctx, listRuntimeUsage, arg.RuntimeID, arg.Limit)
rows, err := q.db.Query(ctx, listRuntimeUsage, arg.RuntimeID, arg.Since)
if err != nil {
return nil, err
}

View File

@@ -12,8 +12,8 @@ DO UPDATE SET
-- name: ListRuntimeUsage :many
SELECT * FROM runtime_usage
WHERE runtime_id = $1
ORDER BY date DESC
LIMIT $2;
AND date >= $2
ORDER BY date DESC;
-- name: GetRuntimeUsageSummary :many
SELECT provider, model,