Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a04b576414 | ||
|
|
76f2635700 | ||
|
|
e2bb299300 | ||
|
|
f5abe9132b | ||
|
|
d55b316d4c | ||
|
|
f7fd30da15 | ||
|
|
90c08a98cd | ||
|
|
d92cfac761 |
@@ -4,12 +4,32 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
pull_request:
|
pull_request:
|
||||||
|
concurrency:
|
||||||
|
group: ci-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
jobs:
|
jobs:
|
||||||
check:
|
check:
|
||||||
name: Full Project Check
|
name: Full Project Check
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
steps:
|
steps:
|
||||||
|
- name: Print runner wait time
|
||||||
|
env:
|
||||||
|
FORGEJO_TOKEN: ${{ github.token }}
|
||||||
|
RUN_NUMBER: ${{ github.run_number }}
|
||||||
|
run: |
|
||||||
|
runner_start=$(date +%s)
|
||||||
|
created_at=$(curl -sf \
|
||||||
|
-H "Authorization: token $FORGEJO_TOKEN" \
|
||||||
|
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/actions/tasks?limit=100" \
|
||||||
|
| python3 -c "import sys,json;data=json.load(sys.stdin);rs=[r for r in data.get('workflow_runs',[]) if r.get('run_number')==$RUN_NUMBER];print(rs[0]['created_at'] if rs else '')" 2>/dev/null)
|
||||||
|
if [ -n "$created_at" ]; then
|
||||||
|
queued_epoch=$(date -d "$created_at" +%s)
|
||||||
|
wait_seconds=$((runner_start - queued_epoch))
|
||||||
|
echo "Runner wait time: ${wait_seconds}s (queued at $created_at)"
|
||||||
|
else
|
||||||
|
echo "Runner wait time: unknown (API lookup failed)"
|
||||||
|
fi
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Setup Dagger Remote Engine
|
- name: Setup Dagger Remote Engine
|
||||||
env:
|
env:
|
||||||
|
|||||||
@@ -15,6 +15,23 @@ jobs:
|
|||||||
linux: ${{ steps.diff.outputs.linux }}
|
linux: ${{ steps.diff.outputs.linux }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- name: Print runner wait time
|
||||||
|
env:
|
||||||
|
FORGEJO_TOKEN: ${{ github.token }}
|
||||||
|
RUN_NUMBER: ${{ github.run_number }}
|
||||||
|
run: |
|
||||||
|
runner_start=$(date +%s)
|
||||||
|
created_at=$(curl -sf \
|
||||||
|
-H "Authorization: token $FORGEJO_TOKEN" \
|
||||||
|
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/actions/tasks?limit=100" \
|
||||||
|
| python3 -c "import sys,json;data=json.load(sys.stdin);rs=[r for r in data.get('workflow_runs',[]) if r.get('run_number')==$RUN_NUMBER];print(rs[0]['created_at'] if rs else '')" 2>/dev/null)
|
||||||
|
if [ -n "$created_at" ]; then
|
||||||
|
queued_epoch=$(date -d "$created_at" +%s)
|
||||||
|
wait_seconds=$((runner_start - queued_epoch))
|
||||||
|
echo "Runner wait time: ${wait_seconds}s (queued at $created_at)"
|
||||||
|
else
|
||||||
|
echo "Runner wait time: unknown (API lookup failed)"
|
||||||
|
fi
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
@@ -141,6 +158,23 @@ jobs:
|
|||||||
if: needs.check-changes.outputs.android == 'true'
|
if: needs.check-changes.outputs.android == 'true'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- name: Print runner wait time
|
||||||
|
env:
|
||||||
|
FORGEJO_TOKEN: ${{ github.token }}
|
||||||
|
RUN_NUMBER: ${{ github.run_number }}
|
||||||
|
run: |
|
||||||
|
runner_start=$(date +%s)
|
||||||
|
created_at=$(curl -sf \
|
||||||
|
-H "Authorization: token $FORGEJO_TOKEN" \
|
||||||
|
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/actions/tasks?limit=100" \
|
||||||
|
| python3 -c "import sys,json;data=json.load(sys.stdin);rs=[r for r in data.get('workflow_runs',[]) if r.get('run_number')==$RUN_NUMBER];print(rs[0]['created_at'] if rs else '')" 2>/dev/null)
|
||||||
|
if [ -n "$created_at" ]; then
|
||||||
|
queued_epoch=$(date -d "$created_at" +%s)
|
||||||
|
wait_seconds=$((runner_start - queued_epoch))
|
||||||
|
echo "Runner wait time: ${wait_seconds}s (queued at $created_at)"
|
||||||
|
else
|
||||||
|
echo "Runner wait time: unknown (API lookup failed)"
|
||||||
|
fi
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 100
|
fetch-depth: 100
|
||||||
@@ -175,6 +209,23 @@ jobs:
|
|||||||
if: needs.check-changes.outputs.android == 'true'
|
if: needs.check-changes.outputs.android == 'true'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- name: Print runner wait time
|
||||||
|
env:
|
||||||
|
FORGEJO_TOKEN: ${{ github.token }}
|
||||||
|
RUN_NUMBER: ${{ github.run_number }}
|
||||||
|
run: |
|
||||||
|
runner_start=$(date +%s)
|
||||||
|
created_at=$(curl -sf \
|
||||||
|
-H "Authorization: token $FORGEJO_TOKEN" \
|
||||||
|
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/actions/tasks?limit=100" \
|
||||||
|
| python3 -c "import sys,json;data=json.load(sys.stdin);rs=[r for r in data.get('workflow_runs',[]) if r.get('run_number')==$RUN_NUMBER];print(rs[0]['created_at'] if rs else '')" 2>/dev/null)
|
||||||
|
if [ -n "$created_at" ]; then
|
||||||
|
queued_epoch=$(date -d "$created_at" +%s)
|
||||||
|
wait_seconds=$((runner_start - queued_epoch))
|
||||||
|
echo "Runner wait time: ${wait_seconds}s (queued at $created_at)"
|
||||||
|
else
|
||||||
|
echo "Runner wait time: unknown (API lookup failed)"
|
||||||
|
fi
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 100
|
fetch-depth: 100
|
||||||
@@ -203,6 +254,23 @@ jobs:
|
|||||||
if: needs.check-changes.outputs.linux == 'true'
|
if: needs.check-changes.outputs.linux == 'true'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- name: Print runner wait time
|
||||||
|
env:
|
||||||
|
FORGEJO_TOKEN: ${{ github.token }}
|
||||||
|
RUN_NUMBER: ${{ github.run_number }}
|
||||||
|
run: |
|
||||||
|
runner_start=$(date +%s)
|
||||||
|
created_at=$(curl -sf \
|
||||||
|
-H "Authorization: token $FORGEJO_TOKEN" \
|
||||||
|
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/actions/tasks?limit=100" \
|
||||||
|
| python3 -c "import sys,json;data=json.load(sys.stdin);rs=[r for r in data.get('workflow_runs',[]) if r.get('run_number')==$RUN_NUMBER];print(rs[0]['created_at'] if rs else '')" 2>/dev/null)
|
||||||
|
if [ -n "$created_at" ]; then
|
||||||
|
queued_epoch=$(date -d "$created_at" +%s)
|
||||||
|
wait_seconds=$((runner_start - queued_epoch))
|
||||||
|
echo "Runner wait time: ${wait_seconds}s (queued at $created_at)"
|
||||||
|
else
|
||||||
|
echo "Runner wait time: unknown (API lookup failed)"
|
||||||
|
fi
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 100
|
fetch-depth: 100
|
||||||
@@ -236,6 +304,23 @@ jobs:
|
|||||||
timeout-minutes: 5
|
timeout-minutes: 5
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- name: Print runner wait time
|
||||||
|
env:
|
||||||
|
FORGEJO_TOKEN: ${{ github.token }}
|
||||||
|
RUN_NUMBER: ${{ github.run_number }}
|
||||||
|
run: |
|
||||||
|
runner_start=$(date +%s)
|
||||||
|
created_at=$(curl -sf \
|
||||||
|
-H "Authorization: token $FORGEJO_TOKEN" \
|
||||||
|
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/actions/tasks?limit=100" \
|
||||||
|
| python3 -c "import sys,json;data=json.load(sys.stdin);rs=[r for r in data.get('workflow_runs',[]) if r.get('run_number')==$RUN_NUMBER];print(rs[0]['created_at'] if rs else '')" 2>/dev/null)
|
||||||
|
if [ -n "$created_at" ]; then
|
||||||
|
queued_epoch=$(date -d "$created_at" +%s)
|
||||||
|
wait_seconds=$((runner_start - queued_epoch))
|
||||||
|
echo "Runner wait time: ${wait_seconds}s (queued at $created_at)"
|
||||||
|
else
|
||||||
|
echo "Runner wait time: unknown (API lookup failed)"
|
||||||
|
fi
|
||||||
- name: Set CI/Full-Pass or CI/Full-Fail label on tracking issue
|
- name: Set CI/Full-Pass or CI/Full-Fail label on tracking issue
|
||||||
env:
|
env:
|
||||||
FORGEJO_TOKEN: ${{ github.token }}
|
FORGEJO_TOKEN: ${{ github.token }}
|
||||||
|
|||||||
@@ -14,6 +14,23 @@ jobs:
|
|||||||
has_changes: ${{ steps.diff.outputs.has_changes }}
|
has_changes: ${{ steps.diff.outputs.has_changes }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- name: Print runner wait time
|
||||||
|
env:
|
||||||
|
FORGEJO_TOKEN: ${{ github.token }}
|
||||||
|
RUN_NUMBER: ${{ github.run_number }}
|
||||||
|
run: |
|
||||||
|
runner_start=$(date +%s)
|
||||||
|
created_at=$(curl -sf \
|
||||||
|
-H "Authorization: token $FORGEJO_TOKEN" \
|
||||||
|
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/actions/tasks?limit=100" \
|
||||||
|
| python3 -c "import sys,json;data=json.load(sys.stdin);rs=[r for r in data.get('workflow_runs',[]) if r.get('run_number')==$RUN_NUMBER];print(rs[0]['created_at'] if rs else '')" 2>/dev/null)
|
||||||
|
if [ -n "$created_at" ]; then
|
||||||
|
queued_epoch=$(date -d "$created_at" +%s)
|
||||||
|
wait_seconds=$((runner_start - queued_epoch))
|
||||||
|
echo "Runner wait time: ${wait_seconds}s (queued at $created_at)"
|
||||||
|
else
|
||||||
|
echo "Runner wait time: unknown (API lookup failed)"
|
||||||
|
fi
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
@@ -50,6 +67,23 @@ jobs:
|
|||||||
if: needs.check-changes.outputs.has_changes == 'true'
|
if: needs.check-changes.outputs.has_changes == 'true'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- name: Print runner wait time
|
||||||
|
env:
|
||||||
|
FORGEJO_TOKEN: ${{ github.token }}
|
||||||
|
RUN_NUMBER: ${{ github.run_number }}
|
||||||
|
run: |
|
||||||
|
runner_start=$(date +%s)
|
||||||
|
created_at=$(curl -sf \
|
||||||
|
-H "Authorization: token $FORGEJO_TOKEN" \
|
||||||
|
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/actions/tasks?limit=100" \
|
||||||
|
| python3 -c "import sys,json;data=json.load(sys.stdin);rs=[r for r in data.get('workflow_runs',[]) if r.get('run_number')==$RUN_NUMBER];print(rs[0]['created_at'] if rs else '')" 2>/dev/null)
|
||||||
|
if [ -n "$created_at" ]; then
|
||||||
|
queued_epoch=$(date -d "$created_at" +%s)
|
||||||
|
wait_seconds=$((runner_start - queued_epoch))
|
||||||
|
echo "Runner wait time: ${wait_seconds}s (queued at $created_at)"
|
||||||
|
else
|
||||||
|
echo "Runner wait time: unknown (API lookup failed)"
|
||||||
|
fi
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 1
|
fetch-depth: 1
|
||||||
|
|||||||
@@ -18,6 +18,23 @@ jobs:
|
|||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- name: Print runner wait time
|
||||||
|
env:
|
||||||
|
FORGEJO_TOKEN: ${{ github.token }}
|
||||||
|
RUN_NUMBER: ${{ github.run_number }}
|
||||||
|
run: |
|
||||||
|
runner_start=$(date +%s)
|
||||||
|
created_at=$(curl -sf \
|
||||||
|
-H "Authorization: token $FORGEJO_TOKEN" \
|
||||||
|
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/actions/tasks?limit=100" \
|
||||||
|
| python3 -c "import sys,json;data=json.load(sys.stdin);rs=[r for r in data.get('workflow_runs',[]) if r.get('run_number')==$RUN_NUMBER];print(rs[0]['created_at'] if rs else '')" 2>/dev/null)
|
||||||
|
if [ -n "$created_at" ]; then
|
||||||
|
queued_epoch=$(date -d "$created_at" +%s)
|
||||||
|
wait_seconds=$((runner_start - queued_epoch))
|
||||||
|
echo "Runner wait time: ${wait_seconds}s (queued at $created_at)"
|
||||||
|
else
|
||||||
|
echo "Runner wait time: unknown (API lookup failed)"
|
||||||
|
fi
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
|
|||||||
+29
-21
@@ -539,7 +539,7 @@ func (m *Ci) TestBackend(ctx context.Context) (string, error) {
|
|||||||
return m.WithStalwart(m.setup(m.backendSrc())).
|
return m.WithStalwart(m.setup(m.backendSrc())).
|
||||||
WithExec([]string{"/bin/bash", "-c",
|
WithExec([]string{"/bin/bash", "-c",
|
||||||
`tmp=$(mktemp); trap 'rm -f "$tmp"' EXIT; ` +
|
`tmp=$(mktemp); trap 'rm -f "$tmp"' EXIT; ` +
|
||||||
`flutter test --concurrency=1 --reporter expanded --no-pub test/backend >"$tmp" 2>&1 || { cat "$tmp"; exit 1; }; ` +
|
`flutter test --concurrency=1 --reporter expanded --no-pub --exclude-tags=nightly test/backend >"$tmp" 2>&1 || { cat "$tmp"; exit 1; }; ` +
|
||||||
`grep -E '^All [0-9]+ tests passed' "$tmp" || tail -1 "$tmp"`}).
|
`grep -E '^All [0-9]+ tests passed' "$tmp" || tail -1 "$tmp"`}).
|
||||||
Stdout(ctx)
|
Stdout(ctx)
|
||||||
}
|
}
|
||||||
@@ -570,7 +570,7 @@ func (m *Ci) ChaosMonkeyBackend(ctx context.Context) (string, error) {
|
|||||||
return m.WithStalwart(m.setup(m.backendSrc())).
|
return m.WithStalwart(m.setup(m.backendSrc())).
|
||||||
WithExec([]string{"/bin/bash", "-c",
|
WithExec([]string{"/bin/bash", "-c",
|
||||||
`tmp=$(mktemp); trap 'rm -f "$tmp"' EXIT; ` +
|
`tmp=$(mktemp); trap 'rm -f "$tmp"' EXIT; ` +
|
||||||
`flutter test test/backend/chaos_monkey_test.dart --reporter expanded --concurrency=1 --no-pub >"$tmp" 2>&1 || { cat "$tmp"; exit 1; }; ` +
|
`flutter test test/backend/chaos_monkey_test.dart --reporter expanded --concurrency=1 --no-pub --tags=nightly >"$tmp" 2>&1 || { cat "$tmp"; exit 1; }; ` +
|
||||||
`grep -E '^All [0-9]+ tests passed' "$tmp" || tail -1 "$tmp"`}).
|
`grep -E '^All [0-9]+ tests passed' "$tmp" || tail -1 "$tmp"`}).
|
||||||
Stdout(ctx)
|
Stdout(ctx)
|
||||||
}
|
}
|
||||||
@@ -594,25 +594,33 @@ func (m *Ci) Check(ctx context.Context) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
checkSetup := m.setup(m.checkSrc())
|
// Run format, analyze, generated-code check, and coverage in parallel —
|
||||||
|
// they all share the same setup base and have no dependencies on each other.
|
||||||
if _, err := checkSetup.WithExec([]string{"dart", "format", "--output=none", "--set-exit-if-changed", "lib", "test"}).Stdout(ctx); err != nil {
|
var analyze, mocks, coverage string
|
||||||
return "Format check failed", err
|
var checkEg errgroup.Group
|
||||||
}
|
checkEg.Go(func() error {
|
||||||
|
setup := m.setup(m.checkSrc())
|
||||||
analyze, err := checkSetup.WithExec([]string{"dart", "analyze", "--fatal-infos"}).Stdout(ctx)
|
_, err := setup.WithExec([]string{"dart", "format", "--output=none", "--set-exit-if-changed", "lib", "test"}).Stdout(ctx)
|
||||||
if err != nil {
|
return err
|
||||||
return analyze, err
|
})
|
||||||
}
|
checkEg.Go(func() error {
|
||||||
|
setup := m.setup(m.checkSrc())
|
||||||
mocks, err := m.CheckGenerated(ctx)
|
var err error
|
||||||
if err != nil {
|
analyze, err = setup.WithExec([]string{"dart", "analyze", "--fatal-infos"}).Stdout(ctx)
|
||||||
return mocks, err
|
return err
|
||||||
}
|
})
|
||||||
|
checkEg.Go(func() error {
|
||||||
coverage, err := m.Coverage(ctx)
|
var err error
|
||||||
if err != nil {
|
mocks, err = m.CheckGenerated(ctx)
|
||||||
return coverage, err
|
return err
|
||||||
|
})
|
||||||
|
checkEg.Go(func() error {
|
||||||
|
var err error
|
||||||
|
coverage, err = m.Coverage(ctx)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
if err := checkEg.Wait(); err != nil {
|
||||||
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use errgroup.Group (not WithContext) so a failing test does not cancel its
|
// Use errgroup.Group (not WithContext) so a failing test does not cancel its
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ abstract class EmailRepository {
|
|||||||
);
|
);
|
||||||
|
|
||||||
/// Searches the local DB across all mailboxes of [accountId] (or all accounts
|
/// Searches the local DB across all mailboxes of [accountId] (or all accounts
|
||||||
/// if null) by subject and preview. Fast, works offline.
|
/// if null) by subject, preview, and notes. Fast, works offline.
|
||||||
Future<List<Email>> searchEmailsGlobal(String? accountId, String query);
|
Future<List<Email>> searchEmailsGlobal(String? accountId, String query);
|
||||||
|
|
||||||
/// Returns all locally cached emails in any mailbox of [accountId] (or all
|
/// Returns all locally cached emails in any mailbox of [accountId] (or all
|
||||||
|
|||||||
@@ -2922,9 +2922,9 @@ class EmailRepositoryImpl implements EmailRepository {
|
|||||||
|
|
||||||
final sql = accountId != null
|
final sql = accountId != null
|
||||||
? 'SELECT e.* FROM email_fts f JOIN emails e ON e.rowid = f.rowid'
|
? 'SELECT e.* FROM email_fts f JOIN emails e ON e.rowid = f.rowid'
|
||||||
' WHERE email_fts MATCH ? AND e.account_id = ? ORDER BY rank LIMIT 50'
|
' WHERE email_fts MATCH ? AND e.account_id = ? ORDER BY e.received_at DESC LIMIT 50'
|
||||||
: 'SELECT e.* FROM email_fts f JOIN emails e ON e.rowid = f.rowid'
|
: 'SELECT e.* FROM email_fts f JOIN emails e ON e.rowid = f.rowid'
|
||||||
' WHERE email_fts MATCH ? ORDER BY rank LIMIT 50';
|
' WHERE email_fts MATCH ? ORDER BY e.received_at DESC LIMIT 50';
|
||||||
final variables = accountId != null
|
final variables = accountId != null
|
||||||
? [Variable<String>(ftsQuery), Variable<String>(accountId)]
|
? [Variable<String>(ftsQuery), Variable<String>(accountId)]
|
||||||
: [Variable<String>(ftsQuery)];
|
: [Variable<String>(ftsQuery)];
|
||||||
@@ -2934,6 +2934,56 @@ class EmailRepositoryImpl implements EmailRepository {
|
|||||||
final emailRows = await Future.wait(
|
final emailRows = await Future.wait(
|
||||||
queryRows.map((r) => _db.emails.mapFromRow(r)),
|
queryRows.map((r) => _db.emails.mapFromRow(r)),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final noteRows = await _searchEmailsByNotes(accountId, null, query);
|
||||||
|
|
||||||
|
final seen = <String>{};
|
||||||
|
final merged = <model.Email>[];
|
||||||
|
for (final e in [...emailRows.map(_toModel), ...noteRows]) {
|
||||||
|
if (seen.add(e.id)) merged.add(e);
|
||||||
|
}
|
||||||
|
merged.sort((a, b) => b.receivedAt.compareTo(a.receivedAt));
|
||||||
|
return merged;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns emails whose associated notes contain all words from [query].
|
||||||
|
/// Optionally filtered by [accountId] and [mailboxPath].
|
||||||
|
Future<List<model.Email>> _searchEmailsByNotes(
|
||||||
|
String? accountId,
|
||||||
|
String? mailboxPath,
|
||||||
|
String query,
|
||||||
|
) async {
|
||||||
|
final words =
|
||||||
|
query.trim().split(RegExp(r'\s+')).where((w) => w.isNotEmpty).toList();
|
||||||
|
if (words.isEmpty) return [];
|
||||||
|
|
||||||
|
final noteConditions = words.map((_) => 'n.note_text LIKE ?').join(' AND ');
|
||||||
|
final likeVars = words.map((w) => Variable<String>('%$w%')).toList();
|
||||||
|
|
||||||
|
final extraConditions = StringBuffer();
|
||||||
|
final extraVars = <Variable<String>>[];
|
||||||
|
if (accountId != null) {
|
||||||
|
extraConditions.write(' AND e.account_id = ?');
|
||||||
|
extraVars.add(Variable<String>(accountId));
|
||||||
|
}
|
||||||
|
if (mailboxPath != null) {
|
||||||
|
extraConditions.write(' AND e.mailbox_path = ?');
|
||||||
|
extraVars.add(Variable<String>(mailboxPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
final sql = 'SELECT DISTINCT e.* FROM emails e'
|
||||||
|
' JOIN email_notes n ON n.message_id = e.message_id'
|
||||||
|
' AND n.account_id = e.account_id'
|
||||||
|
' WHERE $noteConditions$extraConditions'
|
||||||
|
' ORDER BY e.received_at DESC LIMIT 50';
|
||||||
|
|
||||||
|
final rows = await _db.customSelect(
|
||||||
|
sql,
|
||||||
|
variables: [...likeVars, ...extraVars],
|
||||||
|
readsFrom: {_db.emails, _db.emailNotes},
|
||||||
|
).get();
|
||||||
|
final emailRows =
|
||||||
|
await Future.wait(rows.map((r) => _db.emails.mapFromRow(r)));
|
||||||
return emailRows.map(_toModel).toList();
|
return emailRows.map(_toModel).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2943,9 +2993,7 @@ class EmailRepositoryImpl implements EmailRepository {
|
|||||||
static String _toFtsQuery(String query) {
|
static String _toFtsQuery(String query) {
|
||||||
final words = query
|
final words = query
|
||||||
.trim()
|
.trim()
|
||||||
.split(RegExp(r'\s+'))
|
.split(RegExp(r'[^\w]+'))
|
||||||
.where((w) => w.isNotEmpty)
|
|
||||||
.map((w) => w.replaceAll(RegExp(r'[^\w]'), ''))
|
|
||||||
.where((w) => w.isNotEmpty)
|
.where((w) => w.isNotEmpty)
|
||||||
.toList();
|
.toList();
|
||||||
if (words.isEmpty) return '';
|
if (words.isEmpty) return '';
|
||||||
@@ -3047,6 +3095,8 @@ class EmailRepositoryImpl implements EmailRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
// Results are limited to emails already synced into the local SQLite FTS5
|
||||||
|
// index; call syncEmails first to ensure the index is up-to-date.
|
||||||
Future<List<model.Email>> searchEmails(
|
Future<List<model.Email>> searchEmails(
|
||||||
String accountId,
|
String accountId,
|
||||||
String mailboxPath,
|
String mailboxPath,
|
||||||
@@ -3057,7 +3107,7 @@ class EmailRepositoryImpl implements EmailRepository {
|
|||||||
|
|
||||||
const sql = 'SELECT e.* FROM email_fts f JOIN emails e ON e.rowid = f.rowid'
|
const sql = 'SELECT e.* FROM email_fts f JOIN emails e ON e.rowid = f.rowid'
|
||||||
' WHERE email_fts MATCH ? AND e.account_id = ? AND e.mailbox_path = ?'
|
' WHERE email_fts MATCH ? AND e.account_id = ? AND e.mailbox_path = ?'
|
||||||
' ORDER BY rank LIMIT 50';
|
' ORDER BY e.received_at DESC LIMIT 50';
|
||||||
final variables = [
|
final variables = [
|
||||||
Variable<String>(ftsQuery),
|
Variable<String>(ftsQuery),
|
||||||
Variable<String>(accountId),
|
Variable<String>(accountId),
|
||||||
@@ -3069,7 +3119,16 @@ class EmailRepositoryImpl implements EmailRepository {
|
|||||||
final emailRows = await Future.wait(
|
final emailRows = await Future.wait(
|
||||||
queryRows.map((r) => _db.emails.mapFromRow(r)),
|
queryRows.map((r) => _db.emails.mapFromRow(r)),
|
||||||
);
|
);
|
||||||
return emailRows.map(_toModel).toList();
|
|
||||||
|
final noteRows = await _searchEmailsByNotes(accountId, mailboxPath, query);
|
||||||
|
|
||||||
|
final seen = <String>{};
|
||||||
|
final merged = <model.Email>[];
|
||||||
|
for (final e in [...emailRows.map(_toModel), ...noteRows]) {
|
||||||
|
if (seen.add(e.id)) merged.add(e);
|
||||||
|
}
|
||||||
|
merged.sort((a, b) => b.receivedAt.compareTo(a.receivedAt));
|
||||||
|
return merged;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Helpers ────────────────────────────────────────────────────────────────
|
// ── Helpers ────────────────────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ class _SharedInboxAppState extends ConsumerState<SharedInboxApp> {
|
|||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo),
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo),
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
|
splashFactory: NoSplash.splashFactory,
|
||||||
),
|
),
|
||||||
darkTheme: ThemeData(
|
darkTheme: ThemeData(
|
||||||
colorScheme: ColorScheme.fromSeed(
|
colorScheme: ColorScheme.fromSeed(
|
||||||
@@ -116,6 +117,7 @@ class _SharedInboxAppState extends ConsumerState<SharedInboxApp> {
|
|||||||
brightness: Brightness.dark,
|
brightness: Brightness.dark,
|
||||||
),
|
),
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
|
splashFactory: NoSplash.splashFactory,
|
||||||
),
|
),
|
||||||
routerConfig: router,
|
routerConfig: router,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ class CrashScreen extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
|
theme: ThemeData(splashFactory: NoSplash.splashFactory),
|
||||||
home: Scaffold(
|
home: Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('Something went wrong'),
|
title: const Text('Something went wrong'),
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
// CHAOS_ROUNDS (default: 30) — number of random operations to perform
|
// CHAOS_ROUNDS (default: 30) — number of random operations to perform
|
||||||
// CHAOS_SEED (default: current epoch ms) — seed for reproducibility
|
// CHAOS_SEED (default: current epoch ms) — seed for reproducibility
|
||||||
|
|
||||||
|
@Tags(['nightly'])
|
||||||
|
library;
|
||||||
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
@@ -132,7 +135,7 @@ void main() {
|
|||||||
tearDown(() => db.close());
|
tearDown(() => db.close());
|
||||||
|
|
||||||
test('chaos monkey — random operations do not crash the repository',
|
test('chaos monkey — random operations do not crash the repository',
|
||||||
() async {
|
timeout: Timeout.none, () async {
|
||||||
final seedStr = _env('CHAOS_SEED');
|
final seedStr = _env('CHAOS_SEED');
|
||||||
final seed = seedStr.isEmpty
|
final seed = seedStr.isEmpty
|
||||||
? DateTime.now().millisecondsSinceEpoch
|
? DateTime.now().millisecondsSinceEpoch
|
||||||
|
|||||||
@@ -433,6 +433,7 @@ void main() {
|
|||||||
|
|
||||||
final r = makeRepo();
|
final r = makeRepo();
|
||||||
await r.accounts.addAccount(account, userPass);
|
await r.accounts.addAccount(account, userPass);
|
||||||
|
await r.emails.syncEmails('test', 'INBOX');
|
||||||
|
|
||||||
final results = await r.emails.searchEmails(
|
final results = await r.emails.searchEmails(
|
||||||
'test',
|
'test',
|
||||||
|
|||||||
@@ -486,6 +486,158 @@ void main() {
|
|||||||
expect(results.first.mailboxPath, 'INBOX');
|
expect(results.first.mailboxPath, 'INBOX');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('searchEmailsGlobal includes emails matched by note text', () async {
|
||||||
|
final r = _makeRepos();
|
||||||
|
await r.accounts.addAccount(_account, 'pw');
|
||||||
|
|
||||||
|
// Email whose subject does NOT match — but its note does.
|
||||||
|
await r.db.into(r.db.emails).insert(
|
||||||
|
EmailsCompanion.insert(
|
||||||
|
id: 'acc-1:1',
|
||||||
|
accountId: 'acc-1',
|
||||||
|
mailboxPath: 'INBOX',
|
||||||
|
uid: 1,
|
||||||
|
messageId: const Value('<msg1@example.com>'),
|
||||||
|
subject: const Value('Weekly report'),
|
||||||
|
receivedAt: DateTime(2024),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
// Add a note referencing the email's messageId.
|
||||||
|
await r.db.into(r.db.emailNotes).insert(
|
||||||
|
EmailNotesCompanion.insert(
|
||||||
|
id: 'note-1',
|
||||||
|
accountId: 'acc-1',
|
||||||
|
messageId: '<msg1@example.com>',
|
||||||
|
noteText: 'Urgent follow-up needed',
|
||||||
|
serverId: '42',
|
||||||
|
createdAt: DateTime(2024),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final results = await r.emails.searchEmailsGlobal(null, 'urgent');
|
||||||
|
expect(results, hasLength(1));
|
||||||
|
expect(results.first.subject, 'Weekly report');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('searchEmails includes emails matched by note text in mailbox',
|
||||||
|
() async {
|
||||||
|
final r = _makeRepos();
|
||||||
|
await r.accounts.addAccount(_account, 'pw');
|
||||||
|
|
||||||
|
await r.db.into(r.db.emails).insert(
|
||||||
|
EmailsCompanion.insert(
|
||||||
|
id: 'acc-1:1',
|
||||||
|
accountId: 'acc-1',
|
||||||
|
mailboxPath: 'INBOX',
|
||||||
|
uid: 1,
|
||||||
|
messageId: const Value('<msg1@example.com>'),
|
||||||
|
subject: const Value('Project update'),
|
||||||
|
receivedAt: DateTime(2024),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
// Email in a different mailbox — its note must not appear in INBOX search.
|
||||||
|
await r.db.into(r.db.emails).insert(
|
||||||
|
EmailsCompanion.insert(
|
||||||
|
id: 'acc-1:2',
|
||||||
|
accountId: 'acc-1',
|
||||||
|
mailboxPath: 'Sent',
|
||||||
|
uid: 2,
|
||||||
|
messageId: const Value('<msg2@example.com>'),
|
||||||
|
subject: const Value('Other email'),
|
||||||
|
receivedAt: DateTime(2024),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await r.db.into(r.db.emailNotes).insert(
|
||||||
|
EmailNotesCompanion.insert(
|
||||||
|
id: 'note-1',
|
||||||
|
accountId: 'acc-1',
|
||||||
|
messageId: '<msg1@example.com>',
|
||||||
|
noteText: 'remember to call client',
|
||||||
|
serverId: '42',
|
||||||
|
createdAt: DateTime(2024),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await r.db.into(r.db.emailNotes).insert(
|
||||||
|
EmailNotesCompanion.insert(
|
||||||
|
id: 'note-2',
|
||||||
|
accountId: 'acc-1',
|
||||||
|
messageId: '<msg2@example.com>',
|
||||||
|
noteText: 'remember to call client',
|
||||||
|
serverId: '43',
|
||||||
|
createdAt: DateTime(2024),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final results = await r.emails.searchEmails('acc-1', 'INBOX', 'client');
|
||||||
|
expect(results, hasLength(1));
|
||||||
|
expect(results.first.subject, 'Project update');
|
||||||
|
expect(results.first.mailboxPath, 'INBOX');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('searchEmailsGlobal returns results sorted by receivedAt descending',
|
||||||
|
() async {
|
||||||
|
final r = _makeRepos();
|
||||||
|
await r.accounts.addAccount(_account, 'pw');
|
||||||
|
|
||||||
|
await r.db.into(r.db.emails).insert(
|
||||||
|
EmailsCompanion.insert(
|
||||||
|
id: 'acc-1:1',
|
||||||
|
accountId: 'acc-1',
|
||||||
|
mailboxPath: 'INBOX',
|
||||||
|
uid: 1,
|
||||||
|
subject: const Value('Older report'),
|
||||||
|
receivedAt: DateTime(2024),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await r.db.into(r.db.emails).insert(
|
||||||
|
EmailsCompanion.insert(
|
||||||
|
id: 'acc-1:2',
|
||||||
|
accountId: 'acc-1',
|
||||||
|
mailboxPath: 'INBOX',
|
||||||
|
uid: 2,
|
||||||
|
subject: const Value('Newer report'),
|
||||||
|
receivedAt: DateTime(2024, 6),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final results = await r.emails.searchEmailsGlobal(null, 'report');
|
||||||
|
expect(results, hasLength(2));
|
||||||
|
expect(results[0].subject, 'Newer report');
|
||||||
|
expect(results[1].subject, 'Older report');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('searchEmails returns results sorted by receivedAt descending',
|
||||||
|
() async {
|
||||||
|
final r = _makeRepos();
|
||||||
|
await r.accounts.addAccount(_account, 'pw');
|
||||||
|
|
||||||
|
await r.db.into(r.db.emails).insert(
|
||||||
|
EmailsCompanion.insert(
|
||||||
|
id: 'acc-1:1',
|
||||||
|
accountId: 'acc-1',
|
||||||
|
mailboxPath: 'INBOX',
|
||||||
|
uid: 1,
|
||||||
|
subject: const Value('Older meeting'),
|
||||||
|
receivedAt: DateTime(2024),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await r.db.into(r.db.emails).insert(
|
||||||
|
EmailsCompanion.insert(
|
||||||
|
id: 'acc-1:2',
|
||||||
|
accountId: 'acc-1',
|
||||||
|
mailboxPath: 'INBOX',
|
||||||
|
uid: 2,
|
||||||
|
subject: const Value('Newer meeting'),
|
||||||
|
receivedAt: DateTime(2024, 6),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final results = await r.emails.searchEmails('acc-1', 'INBOX', 'meeting');
|
||||||
|
expect(results, hasLength(2));
|
||||||
|
expect(results[0].subject, 'Newer meeting');
|
||||||
|
expect(results[1].subject, 'Older meeting');
|
||||||
|
});
|
||||||
|
|
||||||
test(
|
test(
|
||||||
'searchAddresses returns results sorted by most recently used',
|
'searchAddresses returns results sorted by most recently used',
|
||||||
() async {
|
() async {
|
||||||
|
|||||||
@@ -50,7 +50,10 @@ Widget _buildScreen({List<Account> accounts = const []}) {
|
|||||||
FakeAccountRepository(accounts),
|
FakeAccountRepository(accounts),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
child: const MaterialApp(home: AboutScreen()),
|
child: MaterialApp(
|
||||||
|
theme: ThemeData(splashFactory: NoSplash.splashFactory),
|
||||||
|
home: const AboutScreen(),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user