Editable stage history, auto-ghosting, and an Add-form fix

Stage history editor:
- The edit form's Pipeline section is now the application's history:
  one row per step (stage + date), Add Step and Remove Step, kept in
  date order. The last step is the current stage and the first step's
  date the date applied, replacing the separate Stage and Date Applied
  fields. An application logged after the fact (applied, interviewed,
  rejected) keeps its whole path.
- JobsDatabase::replaceStageHistory() rewrites a job's history in one
  transaction (sorted, repeats collapsed, stage and date applied kept in
  step); StageHistoryModel backs the section; JobsModel::addJob() now
  returns the new id so a new application's history can be saved.
- `kareer history <id> [Stage=YYYY-MM-DD ...]` shows or replaces it.

Auto-ghosting:
- Applications still at Applied with no activity (the later of the
  date applied and the last stage change) for more than 30 days move to
  Ghosted, recorded like any stage change. Runs at startup for GUI and
  CLI, after switching databases, and shortly after the setting changes.
- Preferences gains an Applications section: on/off and the number of
  days (kareerrc [AutoGhost]). The GUI shows a passive notification; the
  CLI notes it on stderr so --json output stays clean.

Fixes:
- The Add Application form pre-filled empty text fields with the word
  "undefined" (typing "a" gave "undefineda"): fields with no value
  reached QML as undefined. Every field now gets a typed default.
- Embed the app icon as the window icon fallback, so the window and
  About page show it when running uninstalled.

Tests: history replacement and the after-the-fact Allstate case, the
ghosting rules (fresh/stale/logged-late/reopened/threshold), and empty
new-form fields.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01BxDf7HqD1xPnsZP8wt3NTk
This commit is contained in:
2026-09-11 17:00:45 -05:00
co-authored by Claude Opus 5
parent 289246a6d0
commit eb47a589cb
24 changed files with 1106 additions and 32 deletions
+1
View File
@@ -46,6 +46,7 @@ add_executable(jobeditmodeltest
../src/jobsdatabase.cpp
../src/jobsmodel.cpp
../src/jobeditmodel.cpp
../src/stagehistorymodel.cpp
../src/jobfieldcatalog.cpp
)
+66 -1
View File
@@ -43,6 +43,12 @@ private Q_SLOTS:
QCOMPARE(valueOf(edit, u"company"_s).toString(), u"Acme Corp"_s);
QCOMPARE(valueOf(edit, u"title"_s).toString(), u"Engineer"_s);
QCOMPARE(valueOf(edit, u"salaryMin"_s).toInt(), 100000);
// The history's first step shows the date applied, not when it was logged.
StageHistoryModel *history = edit.history();
QCOMPARE(history->rowCount(), 1);
QCOMPARE(history->data(history->index(0), StageHistoryModel::StageRole).toString(), u"Applied"_s);
QCOMPARE(history->data(history->index(0), StageHistoryModel::DateRole).toDate(), QDate(2026, 6, 1));
}
void savesEditsToExistingJob()
@@ -79,17 +85,55 @@ private Q_SLOTS:
edit.setEditingJobId(id);
edit.setJobsModel(&jobs);
setValueOf(edit, u"stage"_s, u"Interview"_s);
// Moving the application on is adding a step to its history.
StageHistoryModel *history = edit.history();
history->appendStep();
history->setStage(history->rowCount() - 1, u"Interview"_s);
QVERIFY2(edit.save(), qPrintable(edit.lastError()));
JobsDatabase db;
QCOMPARE(db.jobById(id)->stage, u"Interview"_s);
QCOMPARE(db.jobById(id)->dateApplied, QDate(2026, 6, 1));
const auto transitions = db.stageTransitions();
QCOMPARE(transitions.size(), 2);
QCOMPARE(transitions.last().fromStage, u"Applied"_s);
QCOMPARE(transitions.last().toStage, u"Interview"_s);
}
// Applied, interviewed, then rejected: logged in one go after the fact.
void logsApplicationAfterTheFact()
{
JobsModel jobs;
JobEditModel edit;
edit.setJobsModel(&jobs);
setValueOf(edit, u"company"_s, u"Allstate"_s);
setValueOf(edit, u"title"_s, u"Software Engineer"_s);
StageHistoryModel *history = edit.history();
const auto day = [](int month, int dayOfMonth) {
return QDateTime(QDate(2026, month, dayOfMonth), QTime(9, 0));
};
history->setDate(0, day(8, 1));
history->appendStep();
history->setStage(1, u"Interview"_s);
history->setDate(1, day(8, 15));
history->appendStep();
history->setStage(2, u"Rejected"_s);
history->setDate(2, day(8, 20));
QVERIFY2(edit.save(), qPrintable(edit.lastError()));
JobsDatabase db;
const QList<Job> all = db.allJobs();
QCOMPARE(all.size(), 1);
QCOMPARE(all.first().stage, u"Rejected"_s);
QCOMPARE(all.first().dateApplied, QDate(2026, 8, 1));
const QList<StageStep> steps = db.stageHistory(all.first().id);
QCOMPARE(steps.size(), 3);
QCOMPARE(steps.at(1).stage, u"Interview"_s);
QCOMPARE(steps.at(1).at.toLocalTime().date(), QDate(2026, 8, 15));
QCOMPARE(steps.at(2).at.toLocalTime().date(), QDate(2026, 8, 20));
}
void addsNewJob()
{
JobsModel jobs;
@@ -108,6 +152,27 @@ private Q_SLOTS:
QCOMPARE(all.first().stage, u"Applied"_s);
}
// A new form's text fields must start empty; a missing value showed up
// in QML as the word "undefined".
void newFormFieldsStartEmpty()
{
JobsModel jobs;
JobEditModel edit;
edit.setJobsModel(&jobs);
for (int row = 0; row < edit.rowCount(); ++row) {
const QVariant value = edit.data(edit.index(row), JobEditModel::ValueRole);
const QString id = edit.data(edit.index(row), JobEditModel::FieldIdRole).toString();
QVERIFY2(value.isValid(), qPrintable(id));
}
for (const QString &id : {u"company"_s, u"title"_s, u"location"_s, u"source"_s, u"url"_s, u"contact"_s, u"notes"_s}) {
const QVariant value = valueOf(edit, id);
QCOMPARE(value.typeId(), QMetaType::QString);
QVERIFY2(value.toString().isEmpty(), qPrintable(id));
}
QCOMPARE(valueOf(edit, u"currency"_s).toString(), u"USD"_s);
QCOMPARE(valueOf(edit, u"remoteType"_s).toString(), u"Unspecified"_s);
}
void missingCompanyIsReported()
{
JobsModel jobs;
+146
View File
@@ -7,6 +7,8 @@
#include "jobsdatabase.h"
#include "job.h"
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QTemporaryDir>
#include <QtTest>
@@ -144,6 +146,150 @@ private Q_SLOTS:
QVERIFY(!db.jobById(job.id).has_value());
QVERIFY(db.stageTransitions().isEmpty());
}
void ghostsStaleApplications()
{
QTemporaryDir dir;
const QString path = dbPathIn(dir);
JobsDatabase db(path);
const QDateTime now(QDate(2026, 9, 11), QTime(12, 0), QTimeZone::UTC);
const auto daysAgo = [&](int days) {
return now.addDays(-days);
};
// Still at Applied, nothing for 40 days: ghosted.
const int stale = addJob(db, {});
backdate(path, stale, {daysAgo(40)}, daysAgo(40).date());
// Applied 10 days ago: too recent.
const int fresh = addJob(db, {});
backdate(path, fresh, {daysAgo(10)}, daysAgo(10).date());
// Got a response (Screening) 40 days ago: not ours to ghost.
const int screening = addJob(db, {QStringLiteral("Screening")});
backdate(path, screening, {daysAgo(45), daysAgo(40)}, daysAgo(45).date());
// Applied 60 days ago but only logged 5 days ago: the month starts at logging.
const int loggedLate = addJob(db, {});
backdate(path, loggedLate, {daysAgo(5)}, daysAgo(60).date());
// Logged 40 days ago, date applied later edited to 10 days ago.
const int appliedLater = addJob(db, {});
backdate(path, appliedLater, {daysAgo(40)}, daysAgo(10).date());
// Ghosted before, then moved back to Applied 5 days ago: a fresh month.
const int reopened = addJob(db, {QStringLiteral("Ghosted"), QStringLiteral("Applied")});
backdate(path, reopened, {daysAgo(60), daysAgo(50), daysAgo(5)}, daysAgo(60).date());
QCOMPARE(db.ghostStaleApplications(0, now), 0);
QCOMPARE(db.ghostStaleApplications(30, now), 1);
QCOMPARE(db.jobById(stale)->stage, QStringLiteral("Ghosted"));
for (int id : {fresh, loggedLate, appliedLater, reopened}) {
QCOMPARE(db.jobById(id)->stage, QStringLiteral("Applied"));
}
QCOMPARE(db.jobById(screening)->stage, QStringLiteral("Screening"));
// Recorded like any other move, so the pipeline shows it.
bool recorded = false;
for (const StageTransition &t : db.stageTransitions()) {
recorded |= t.jobId == stale && t.fromStage == QStringLiteral("Applied") && t.toStage == QStringLiteral("Ghosted");
}
QVERIFY(recorded);
// Nothing left to do on a second run; a shorter threshold catches more.
QCOMPARE(db.ghostStaleApplications(30, now), 0);
QCOMPARE(db.ghostStaleApplications(7, now), 2); // fresh and appliedLater, both 10 days
}
// Logging an application after the fact: Applied, Interview, Rejected.
void replacesStageHistory()
{
QTemporaryDir dir;
JobsDatabase db(dbPathIn(dir));
const int id = addJob(db, {});
const auto at = [](int month, int day) {
return QDateTime(QDate(2026, month, day), QTime(12, 0));
};
// Out of order and with a repeated stage, as an editor might hand it over.
QVERIFY2(db.replaceStageHistory(id,
{{QStringLiteral("rejected"), at(8, 20)},
{QStringLiteral("Applied"), at(8, 1)},
{QStringLiteral("Interview"), at(8, 15)},
{QStringLiteral("Interview"), at(8, 16)}}),
qPrintable(db.lastError()));
const QList<StageStep> steps = db.stageHistory(id);
QCOMPARE(steps.size(), 3);
QCOMPARE(steps.at(0).stage, QStringLiteral("Applied"));
QCOMPARE(steps.at(1).stage, QStringLiteral("Interview"));
QCOMPARE(steps.at(2).stage, QStringLiteral("Rejected"));
QCOMPARE(steps.at(1).at.toLocalTime().date(), QDate(2026, 8, 15));
const auto job = db.jobById(id);
QCOMPARE(job->stage, QStringLiteral("Rejected"));
QCOMPARE(job->dateApplied, QDate(2026, 8, 1));
// The moves chain from the synthetic Start, so the pipeline sees the path.
QStringList moves;
for (const StageTransition &t : db.stageTransitions()) {
if (t.jobId == id) {
moves.append((t.fromStage.isEmpty() ? QStringLiteral("Start") : t.fromStage) + QStringLiteral(">") + t.toStage);
}
}
QCOMPARE(moves, (QStringList{QStringLiteral("Start>Applied"), QStringLiteral("Applied>Interview"), QStringLiteral("Interview>Rejected")}));
// Bad input changes nothing.
QVERIFY(!db.replaceStageHistory(id, {}));
QVERIFY(!db.replaceStageHistory(id, {{QStringLiteral("Applied"), at(8, 1)}, {QStringLiteral("Bogus"), at(8, 2)}}));
QVERIFY(!db.replaceStageHistory(id, {{QStringLiteral("Applied"), QDateTime()}}));
QVERIFY(!db.replaceStageHistory(9999, {{QStringLiteral("Applied"), at(8, 1)}}));
QCOMPARE(db.stageHistory(id).size(), 3);
QCOMPARE(db.jobById(id)->stage, QStringLiteral("Rejected"));
}
private:
static int addJob(JobsDatabase &db, const QStringList &stages)
{
Job job;
job.company = QStringLiteral("Co");
job.title = QStringLiteral("Title");
if (!db.addJob(job)) {
return -1;
}
for (const QString &stage : stages) {
db.setStage(job.id, stage);
}
return job.id;
}
/// Rewrites a job's history timestamps (oldest first, one per recorded
/// move) and its date applied, through a separate connection.
static void backdate(const QString &path, int jobId, const QList<QDateTime> &history, const QDate &applied)
{
{
QSqlDatabase raw = QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"), QStringLiteral("backdate"));
raw.setDatabaseName(path);
QVERIFY(raw.open());
QSqlQuery ids(raw);
QVERIFY(ids.exec(QStringLiteral("SELECT id FROM stage_history WHERE job_id = %1 ORDER BY id").arg(jobId)));
QList<int> rows;
while (ids.next()) {
rows.append(ids.value(0).toInt());
}
QCOMPARE(rows.size(), history.size());
QSqlQuery update(raw);
for (int i = 0; i < rows.size(); ++i) {
update.prepare(QStringLiteral("UPDATE stage_history SET changed_at = ? WHERE id = ?"));
update.addBindValue(history.at(i).toString(Qt::ISODate));
update.addBindValue(rows.at(i));
QVERIFY(update.exec());
}
update.prepare(QStringLiteral("UPDATE jobs SET date_applied = ?, created_at = ? WHERE id = ?"));
update.addBindValue(applied.toString(Qt::ISODate));
update.addBindValue(history.first().toString(Qt::ISODate));
update.addBindValue(jobId);
QVERIFY(update.exec());
raw.close();
}
QSqlDatabase::removeDatabase(QStringLiteral("backdate"));
}
};
QTEST_GUILESS_MAIN(JobsDatabaseTest)