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
2 changes: 1 addition & 1 deletion scripts/check-code-health.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const productionPaths = [
const sourceExtensions = new Set(['.js', '.jsx', '.mjs', '.mts', '.swift', '.ts', '.tsx']);
const baselines = {
complexity: { violations: 30, maxCcn: 98, maxLength: 616, maxParams: 19 },
duplication: { clones: 18, duplicatedLines: 234 },
duplication: { clones: 18, duplicatedLines: 217 },
unused: {
files: 0,
exports: 5,
Expand Down
11 changes: 2 additions & 9 deletions src/lib/local-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from './food-library';
import { entriesWithinRange } from './history';
import { createJournalExport } from './journal-export';
import { sumNutrients } from './nutrients';
import { activeMedications, upsertMedicationCheckIn } from './medications';
import {
calculateCompletedFasts,
Expand Down Expand Up @@ -321,15 +322,7 @@ export function localDashboard(): Dashboard {
.filter((entry) => entry.drankAt >= range.start && entry.drankAt < range.end)
.sort((a, b) => b.drankAt - a.drankAt);
const latestWeight = [...state.weights].sort((a, b) => b.recordedAt - a.recordedAt)[0] ?? null;
const nutrients = entries.reduce(
(total, entry) => ({
calories: total.calories + entry.calories,
carbsG: total.carbsG + entry.carbsG,
proteinG: total.proteinG + entry.proteinG,
fibreG: total.fibreG + entry.fibreG,
}),
{ calories: 0, carbsG: 0, proteinG: 0, fibreG: 0 }
);
const nutrients = sumNutrients(entries);
return {
profile: state.profile,
foods: foodsByLifecycle(state.foods, 'active').sort(
Expand Down
13 changes: 13 additions & 0 deletions src/lib/nutrients.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Nutrients } from './types';

export function sumNutrients(entries: Iterable<Nutrients>): Nutrients {
return [...entries].reduce(
(total, entry) => ({
calories: total.calories + entry.calories,
carbsG: total.carbsG + entry.carbsG,
proteinG: total.proteinG + entry.proteinG,
fibreG: total.fibreG + entry.fibreG,
}),
{ calories: 0, carbsG: 0, proteinG: 0, fibreG: 0 }
);
}
15 changes: 9 additions & 6 deletions src/mcp-source.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { readFileSync } from 'node:fs';
import { readdirSync, readFileSync } from 'node:fs';
import { describe, expect, it } from 'vitest';

const worker = readFileSync(new URL('./worker.ts', import.meta.url), 'utf8');
const worker = [
readFileSync(new URL('./worker.ts', import.meta.url), 'utf8'),
...readdirSync(new URL('./worker/', import.meta.url))
.filter((name) => name.endsWith('.ts'))
.sort()
.map((name) => readFileSync(new URL(`./worker/${name}`, import.meta.url), 'utf8')),
].join('\n');
const migration = readFileSync(
new URL('../migrations/0006_mcp_read_tokens.sql', import.meta.url),
'utf8'
);
const tokenSource = readFileSync(new URL('./server/read-tokens.ts', import.meta.url), 'utf8');
const mcpReads = worker.slice(
worker.indexOf("app.get('/api/mcp/daily'"),
worker.indexOf('app.notFound')
);
const mcpReads = readFileSync(new URL('./worker/mcp.ts', import.meta.url), 'utf8');

describe('Calorie MCP source boundary', () => {
it('stores only a hash and revokes tokens within the signed-in owner', () => {
Expand Down
Loading
Loading