Skip to content

Commit d78169d

Browse files
committed
Intermediate commit: prepare improved scorecard
Signed-off-by: Matthias Büchse <matthias.buechse@alasca.cloud>
1 parent bd33382 commit d78169d

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

Tests/cli.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def _update_scorecard(scorecard, report, testcase_lookup):
8585
raise RuntimeError('subjects do not match')
8686
if scopeuuid != scorecard.setdefault('scope', scopeuuid):
8787
raise RuntimeError('scopes do not match')
88-
scores = scorecard.setdefault('tests', {})
88+
scores = scorecard.setdefault('results', {})
89+
uuid = report['uuid']
8990
checked_at = report['checked_at']
9091
checked_at_str = str(checked_at)[:19]
9192
for tc_id, result in report.get('tests', {}).items():
@@ -94,16 +95,27 @@ def _update_scorecard(scorecard, report, testcase_lookup):
9495
testcase = testcase_lookup.get(tc_id)
9596
lifetime = testcase.get('lifetime') # leave None if not present; to be handled by add_period
9697
expires_at = add_period(checked_at, lifetime)
97-
scores[tc_id] = {'checked_at': checked_at_str, 'expires_at': str(expires_at), **result}
98+
scores[tc_id] = {
99+
'report': uuid,
100+
'checked_at': checked_at_str,
101+
'expires_at': str(expires_at),
102+
**result
103+
}
98104

99105

100-
def _prune_scorecard(scorecard):
101-
scores = scorecard.setdefault('tests', {})
106+
def _prune_scorecard(scorecard, testcase_lookup, grace_period_days=7):
107+
scores = scorecard.setdefault('results', {})
102108
now_str = str(datetime.datetime.now())[:19]
109+
grace_str = str(datetime.datetime.now() - datetime.timedelta(days=grace_period_days))[:19]
103110
for tc_id in list(scores):
104111
score = scores[tc_id]
105-
if score['expires_at'] >= now_str:
106-
del scores[tc_id]
112+
# keep results for known testcases if they haven't expired
113+
if tc_id in testcase_lookup and score['expires_at'] < now_str:
114+
continue
115+
# keep results for unknown testcases for a week to leave time for migration
116+
if score['checked_at'] > grace_str:
117+
continue
118+
del scores[tc_id]
107119

108120

109121
def _atomic_write(path, text):
@@ -156,9 +168,11 @@ def score(specpath, subject, score_yaml, report_yaml):
156168
report_yaml = f'report-{ts}-{subject}.yaml'
157169
_atomic_write(report_yaml, _dump(report))
158170
if score_yaml:
159-
_prune_scorecard(scorecard)
171+
_prune_scorecard(scorecard, spec['testcases'])
160172
_update_scorecard(scorecard, report, spec['testcases'])
161173
_atomic_write(score_yaml, _dump(scorecard))
174+
# collect report uuids
175+
# prune reports
162176

163177

164178
@cli.command()
@@ -170,7 +184,7 @@ def init(specpath, subject, score_yaml):
170184
scorecard = {
171185
'subject': subject,
172186
'scope': spec['uuid'],
173-
'tests': {},
187+
'results': {},
174188
}
175189
_atomic_write(score_yaml, _dump(scorecard))
176190

0 commit comments

Comments
 (0)