Skip to content

Commit 238f6ab

Browse files
committed
Add Regressionable
Issue #123. This is not a real bot, and in fact I'm doubtful that it is useful at all. Even though I successfully used it to find a bunch of regressions, I don't think it should be part of the whateverable project. In any case, for now let's have it committed somewhere.
1 parent 0eba779 commit 238f6ab

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed

bin/Regressionable.p6

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#!/usr/bin/env perl6
2+
# Copyright © 2016-2017
3+
# Aleks-Daniel Jakimenko-Aleksejev <alex.jakimenko@gmail.com>
4+
# Copyright © 2016
5+
# Daniel Green <ddgreen@gmail.com>
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Affero General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Affero General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Affero General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
20+
use Whateverable;
21+
use Misc;
22+
23+
use IRC::Client;
24+
use JSON::Fast;
25+
26+
my $RESULT-DIR = data/regressionable/.IO;
27+
my $CACHE-DIR = data/irc/.IO;
28+
my $LINK = https://irclog.perlgeek.de;
29+
my $CUTOFF = 11631117; # 11631117 is ≈2015-12-01
30+
31+
my $IGNORE = /:i «[rand|pick|roll|rm|shell|run|qx|qqx|slurp|spurt|nativecall]» /;
32+
my @REVISIONS = <2015.12 2016.06 2016.12 2017.06 f72be0f130cf>;
33+
34+
multi sub MAIN(populate) {
35+
mkdir $RESULT-DIR;
36+
for $CACHE-DIR.dir(test => *.ends-with: .cache) {
37+
my $channel = .basename.subst(/ ^‘#’ /, ).subst(/ ‘.cache’$ /, );
38+
for .split(\0\0) {
39+
my ($text, $id, $date) = .split: \0;
40+
next unless /^ [m|r|p6]: /;
41+
$text .= subst: /.+? : \s?/, ;
42+
die Empty message id unless $id;
43+
die Non-numeric message id unless +$id;
44+
my $snippet-path = $RESULT-DIR.add($id);
45+
next if $snippet-path.d; # already exists
46+
mkdir $snippet-path;
47+
spurt $snippet-path.add(snippet), $text\n;
48+
spurt $snippet-path.add(link), $LINK/$channel/$date#i_$id\n;
49+
}
50+
}
51+
}
52+
53+
multi sub MAIN() {
54+
my @full-commits = @REVISIONS.map: &to-full-commit;
55+
for $RESULT-DIR.dir.grep(*.basename > $CUTOFF).pick(*) {
56+
my $status = .add(status);
57+
next if $status.e;
58+
my $snippet = .add(snippet);
59+
my $sneak-peek = .add(sneak-peek);
60+
my $code = $snippet.slurp.chomp;
61+
next if $code ~~ $IGNORE;
62+
I'm-alive;
63+
#say $code;
64+
#prompt ‘OK?’;
65+
66+
my @output = do for @full-commits {
67+
subprocess-commit , $snippet.absolute, $_
68+
}
69+
if [eq] @output {
70+
spurt $status, stable\n;
71+
#say ‘it's fine’;
72+
next
73+
}
74+
my $peek = $code\n\n;
75+
@output .= map: { shorten $_, 800 };
76+
for @REVISIONS Z=> @output {
77+
$peek ~= \n¦«{.key}»:\n{.value}\n
78+
}
79+
spurt $status, unstable\n;
80+
spurt $sneak-peek, $peek;
81+
note Processed {.basename};
82+
#say $peek;
83+
last if $++ > 50; # restart sometimes to free memory :(
84+
}
85+
}
86+
87+
my $help = Commands:
88+
(o)k – the output is correct on HEAD
89+
ski(p) – you don't know yet
90+
(i)nvalid – the snippet is meaningless
91+
(f)uck – go back if you fucked up;
92+
93+
multi sub MAIN(play) {
94+
say $help;
95+
96+
say ;
97+
say Hold on…;
98+
99+
my @snippets = $RESULT-DIR.dir.grep(*.add(status).e).map(+*.basename).sort().reverse;
100+
my @unstable;
101+
102+
for @snippets {
103+
my $status = $RESULT-DIR.add($_).add(status).slurp.chomp;
104+
@unstable.push: $_ if $status eq unstable;
105+
}
106+
say {+@snippets} snippets tested, {+@unstable} are known to be unstable;
107+
prompt Press Enter to play;
108+
109+
loop (my $i = 0; $i < @unstable;) {
110+
$i += check @unstable[$i]
111+
}
112+
}
113+
114+
sub check($id) {
115+
my $status-file = $RESULT-DIR.add($id).add(status);
116+
my $status = $status-file.slurp.chomp;
117+
my $sneak-peek = $RESULT-DIR.add($id).add(sneak-peek);
118+
my $link = $RESULT-DIR.add($id).add(link).slurp;
119+
say ---------------------------------------------------\n\n\n\n\n;
120+
121+
say Code:;
122+
123+
run :in($*IN), :out($*OUT), less, --RAW-CONTROL-CHARS,
124+
--quit-if-one-screen, --no-init, --,
125+
$sneak-peek;
126+
127+
say \n;
128+
say Possible IRC discussion: $link\n;
129+
130+
given prompt Your answer: {
131+
when o { spurt $status-file, ok({@REVISIONS.tail})\n; 1 }
132+
when i { spurt $status-file, invalid\n; 1 }
133+
when f { -1 }
134+
when /^‘p’ \s* (\d+)?/ { try +($0 // 1) // 0 }
135+
default { say I'm sorry Dave, I'm afraid I can't do that\n$help;
136+
prompt Press Enter if you understand;
137+
0 }
138+
}
139+
}
140+
141+
# vim: expandtab shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)