Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions .codex/environments/environment.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ version = 1
name = "dayova-mvp"

[setup]
script = '''
node -e "const fs=require('fs'); const path=require('path'); const {spawnSync}=require('child_process'); const source=process.env.CODEX_SOURCE_TREE_PATH; const worktree=process.env.CODEX_WORKTREE_PATH; if (!source || !worktree) throw new Error('Missing CODEX_SOURCE_TREE_PATH or CODEX_WORKTREE_PATH'); const from=path.join(source,'.env.local'); const to=path.join(worktree,'.env.local'); if (fs.existsSync(from)) fs.copyFileSync(from,to); else console.warn('Missing '+from+'; skipping .env.local copy'); const command=process.platform==='win32'?'corepack.cmd':'corepack'; const result=spawnSync(command,['pnpm','install','--frozen-lockfile'],{cwd:worktree,stdio:'inherit',shell:process.platform==='win32'}); process.exit(result.status ?? 1);"
script = "node -e \"const fs=require('fs'); const path=require('path'); const {spawnSync}=require('child_process'); const source=process.env.CODEX_SOURCE_TREE_PATH; const worktree=process.env.CODEX_WORKTREE_PATH; if (!source || !worktree) throw new Error('Missing CODEX_SOURCE_TREE_PATH or CODEX_WORKTREE_PATH'); const from=path.join(source,'.env.local'); const to=path.join(worktree,'.env.local'); if (fs.existsSync(from)) fs.copyFileSync(from,to); else console.warn('Missing '+from+'; skipping .env.local copy'); const command=process.platform==='win32'?'corepack.cmd':'corepack'; const result=spawnSync(command,['pnpm','install','--frozen-lockfile'],{cwd:worktree,stdio:'inherit',shell:process.platform==='win32'}); process.exit(result.status ?? 1);\""

[[actions]]
name = "Run on ios in dev"
icon = "tool"
command = '''
pnpm i
pnpm ios
'''
12 changes: 12 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY=
CLERK_JWT_ISSUER_DOMAIN=


# -----------------------------------------------------------------------------
# Expo / React Native app runtime: PostHog validation analytics
#
# Optional. The app starts without these values, but validation analytics events
# are only sent when EXPO_PUBLIC_POSTHOG_API_KEY is set.
# Use the EU ingestion host unless the PostHog project lives in another region.
# -----------------------------------------------------------------------------

EXPO_PUBLIC_POSTHOG_API_KEY=
EXPO_PUBLIC_POSTHOG_HOST=https://eu.i.posthog.com


# -----------------------------------------------------------------------------
# Convex backend envs: Lernplan file storage
# Set in Convex, not in Expo/EAS public envs.
Expand Down
1 change: 1 addition & 0 deletions app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const config: ExpoConfig = {
"Dayova braucht Zugriff auf deine Fotos, damit du Schulmaterial hochladen kannst.",
},
],
"expo-localization",
"./plugins/withNinjaLongPaths",
"./plugins/withAndroidPackagingOptions",
[
Expand Down
2 changes: 2 additions & 0 deletions convex/_generated/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type * as notifications from "../notifications.js";
import type * as scheduleConflicts from "../scheduleConflicts.js";
import type * as topicDescriptionValidation from "../topicDescriptionValidation.js";
import type * as users from "../users.js";
import type * as validationAnalytics from "../validationAnalytics.js";

import type {
ApiFromModules,
Expand All @@ -44,6 +45,7 @@ declare const fullApi: ApiFromModules<{
scheduleConflicts: typeof scheduleConflicts;
topicDescriptionValidation: typeof topicDescriptionValidation;
users: typeof users;
validationAnalytics: typeof validationAnalytics;
}>;

/**
Expand Down
35 changes: 35 additions & 0 deletions convex/dayEntries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ type OptionalEntryFields = {
durationMinutes?: number;
examTypeLabel?: string;
completed?: boolean;
executionStatus?:
| "notStarted"
| "started"
| "completed"
| "partiallyCompleted"
| "missed"
| "adjusted";
startedAt?: number;
outcomeAt?: number;
missedReason?:
| "no_time"
| "forgot"
| "no_motivation"
| "too_hard"
| "too_big"
| "unclear"
| "other";
adjustedFromSessionId?: Id<"learningPlanSessions">;
relatedLearningPlanId?: Id<"learningPlans">;
relatedLearningPlanSessionId?: Id<"learningPlanSessions">;
};
Expand Down Expand Up @@ -45,6 +63,17 @@ const optionalEntryFields = (
? { examTypeLabel: entry.examTypeLabel }
: {}),
...(entry.completed !== undefined ? { completed: entry.completed } : {}),
...(entry.executionStatus !== undefined
? { executionStatus: entry.executionStatus }
: {}),
...(entry.startedAt !== undefined ? { startedAt: entry.startedAt } : {}),
...(entry.outcomeAt !== undefined ? { outcomeAt: entry.outcomeAt } : {}),
...(entry.missedReason !== undefined
? { missedReason: entry.missedReason }
: {}),
...(entry.adjustedFromSessionId !== undefined
? { adjustedFromSessionId: entry.adjustedFromSessionId }
: {}),
...(entry.relatedLearningPlanId !== undefined
? { relatedLearningPlanId: entry.relatedLearningPlanId }
: {}),
Expand Down Expand Up @@ -75,6 +104,12 @@ const publicLearningSessionEntry = (
plannedDateLabel: session.dateLabel,
durationMinutes: session.durationMinutes,
completed: session.completed ?? false,
executionStatus:
session.executionStatus ?? (session.completed ? "completed" : "notStarted"),
startedAt: session.startedAt,
outcomeAt: session.outcomeAt,
missedReason: session.missedReason,
adjustedFromSessionId: session.adjustedFromSessionId,
relatedLearningPlanId: session.learningPlanId,
relatedLearningPlanSessionId: session._id,
});
Expand Down
176 changes: 176 additions & 0 deletions convex/learningPlans.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,46 @@ const createPlan = async (t: TestBackend) => {
});
};

const createAcceptedPlanWithSession = async (
t: TestBackend,
overrides: Partial<{
phase: "theory" | "practice" | "rehearsal";
title: string;
dateKey: string;
dateLabel: string;
startTime: string;
durationMinutes: number;
}> = {},
) => {
const learningPlanId = await createPlan(t);
await t.mutation(internal.learningPlans.replaceGeneratedSessions, {
learningPlanId,
knowledgeAnswersJson: "[]",
sourceSummary: "Testmaterial",
insight: { summary: "Bereit zum Lernen.", strengths: [], gaps: [] },
sessions: [
{
phase: overrides.phase ?? "practice",
title: overrides.title ?? "Üben",
dateKey: overrides.dateKey ?? "2026-06-01",
dateLabel: overrides.dateLabel ?? "1. Juni 2026",
startTime: overrides.startTime ?? "17:00",
durationMinutes: overrides.durationMinutes ?? 30,
goal: "Kurz wiederholen.",
tasks: ["Begriffe prüfen", "Aufgaben lösen"],
expectedOutcome: "Du bist vorbereitet.",
},
],
});
await t.mutation(api.learningPlans.acceptPlan, { learningPlanId });
const snapshot = await t.query(api.learningPlans.getSnapshot, {
id: learningPlanId,
});
const session = snapshot?.sessions[0];
if (!session) throw new Error("Expected an accepted learning plan session.");
return { learningPlanId, session };
};

beforeEach(() => {
vi.useFakeTimers();
vi.setSystemTime(new Date("2026-05-30T10:00:00.000Z"));
Expand Down Expand Up @@ -292,6 +332,142 @@ test("review sessions are only synced after the plan is accepted", async () => {
expect(afterAccept["2026-06-04"]?.[0]?.kind).toBe("Lernen");
});

test("learning plan sessions move from started to completed and sync calendar state", async () => {
const t = convexTest(schema, modules).withIdentity(user);
const { learningPlanId, session } = await createAcceptedPlanWithSession(t);

const started = await t.mutation(api.learningPlans.startSession, {
sessionId: session.id,
});
expect(started).toMatchObject({
learningPlanId,
learningPlanSessionId: session.id,
phase: "practice",
plannedDayKey: "2026-06-01",
});

let snapshot = await t.query(api.learningPlans.getSnapshot, {
id: learningPlanId,
});
expect(snapshot?.sessions[0]).toMatchObject({
executionStatus: "started",
completed: false,
});
let entries = await t.query(api.dayEntries.listByDayKeys, {
dayKeys: ["2026-06-01"],
});
expect(entries["2026-06-01"]?.[0]).toMatchObject({
executionStatus: "started",
completed: false,
});

const completed = await t.mutation(api.learningPlans.recordSessionOutcome, {
sessionId: session.id,
outcome: "completed",
});
expect(completed).toMatchObject({
outcome: "completed",
learningPlanSessionId: session.id,
});

snapshot = await t.query(api.learningPlans.getSnapshot, {
id: learningPlanId,
});
expect(snapshot?.sessions[0]).toMatchObject({
executionStatus: "completed",
completed: true,
});
entries = await t.query(api.dayEntries.listByDayKeys, {
dayKeys: ["2026-06-01"],
});
expect(entries["2026-06-01"]?.[0]).toMatchObject({
executionStatus: "completed",
completed: true,
});
});

test("recording a learning plan session outcome requires the session to be started", async () => {
const t = convexTest(schema, modules).withIdentity(user);
const { session } = await createAcceptedPlanWithSession(t);

await expect(
t.mutation(api.learningPlans.recordSessionOutcome, {
sessionId: session.id,
outcome: "completed",
}),
).rejects.toThrow("Starte den Lernblock zuerst.");
});

test("partially completed learning plan sessions stay incomplete but keep the outcome", async () => {
const t = convexTest(schema, modules).withIdentity(user);
const { learningPlanId, session } = await createAcceptedPlanWithSession(t, {
dateKey: "2026-06-02",
dateLabel: "2. Juni 2026",
});

await t.mutation(api.learningPlans.startSession, { sessionId: session.id });
await t.mutation(api.learningPlans.recordSessionOutcome, {
sessionId: session.id,
outcome: "partiallyCompleted",
});

const snapshot = await t.query(api.learningPlans.getSnapshot, {
id: learningPlanId,
});
expect(snapshot?.sessions[0]).toMatchObject({
executionStatus: "partiallyCompleted",
completed: false,
});
const entries = await t.query(api.dayEntries.listByDayKeys, {
dayKeys: ["2026-06-02"],
});
expect(entries["2026-06-02"]?.[0]).toMatchObject({
executionStatus: "partiallyCompleted",
completed: false,
});
});

test("missed learning plan sessions can be adjusted into a linked recovery block", async () => {
const t = convexTest(schema, modules).withIdentity(user);
const { learningPlanId, session } = await createAcceptedPlanWithSession(t, {
dateKey: "2026-06-03",
dateLabel: "3. Juni 2026",
});

await t.mutation(api.learningPlans.missSession, {
sessionId: session.id,
reason: "no_time",
});
const adjusted = await t.mutation(api.learningPlans.adjustMissedSession, {
sessionId: session.id,
dateKey: "2026-06-03",
dateLabel: "3. Juni 2026",
startTime: "17:30",
durationMinutes: 15,
});

expect(adjusted).toMatchObject({
learningPlanSessionId: session.id,
newDateKey: "2026-06-03",
newDurationMinutes: 15,
missedReason: "no_time",
});
const snapshot = await t.query(api.learningPlans.getSnapshot, {
id: learningPlanId,
});
expect(snapshot?.sessions).toHaveLength(2);
expect(snapshot?.sessions[0]).toMatchObject({
executionStatus: "adjusted",
missedReason: "no_time",
completed: false,
});
expect(snapshot?.sessions[1]).toMatchObject({
adjustedFromSessionId: session.id,
executionStatus: "notStarted",
durationMinutes: 15,
});
});

test("generated plans can advance to review without available sessions", async () => {
const t = convexTest(schema, modules).withIdentity(user);
const learningPlanId = await createPlan(t);
Expand Down
Loading