Skip to content

Commit 1b6ef5f

Browse files
committed
tools/content: Add wrapper script check-features.
Some main benefits of having a wrapper script to access dart code are that we can provide a more intuitive interface consistent with other tools, for fetching message corpuses and/or running the check for unimplemented features. Very rarely, you might want to use fetch_messages.dart directly, to use the `fetch-newer` flag for example to update a existing corpus file. If we find it helpful, the flag can be added to check-features as well, but we are skipping that for now. The script is intended to be run manually, not as a part of the CI, because it is very slow, and it relies on some out of tree files like API configs (zuliprc files) and big dumps of chat history. Fixes: zulip#190
1 parent e16357b commit 1b6ef5f

File tree

4 files changed

+118
-2
lines changed

4 files changed

+118
-2
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@ app.*.map.json
5353

5454
# Old scaffolding hack
5555
lib/credential_fixture.dart
56+
57+
# Directories used by `tools/check parser`
58+
.corpuses
59+
.api_configs

tools/content/check-features

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
default_steps=(fetch check)
5+
6+
usage() {
7+
cat <<EOF
8+
usage: tools/content/check-features [OPTION]... [STEP]... <CORPUS_DIR>
9+
10+
Fetch messages from a Zulip server and check the content parser for
11+
unimplemented features.
12+
13+
By default, run the following steps:
14+
${default_steps[*]}
15+
16+
CORPUS_DIR is the directory to store or read corpus files. It will be created
17+
if it does not exist already.
18+
19+
The steps are:
20+
21+
fetch Fetch the corpuses needed from the server specified \`--config\`
22+
file into \`CORPUS_DIR\` incrementally. This step can take a long
23+
time on servers with a lot of public messages when starting from
24+
scratch.
25+
This wraps around tools/content/fetch_messages.dart.
26+
27+
check Check for unimplemented content parser features. This requires
28+
the corpus directory \`CORPUS_DIR\` to contain at least one corpus
29+
file.
30+
This wraps around tools/content/unimplemented_features_test.dart.
31+
32+
Options:
33+
34+
--config <FILE>
35+
A zuliprc file with identity information including email, API key
36+
and the Zulip server URL to fetch the messages from.
37+
Mandatory if running step \`fetch\`. To get the file, see
38+
https://zulip.com/api/configuring-python-bindings#download-a-zuliprc-file.
39+
40+
--verbose Print more details about everything, especially when checking for
41+
unsupported features.
42+
43+
--help Show this help message.
44+
EOF
45+
}
46+
47+
opt_corpus_dir=
48+
opt_zuliprc=
49+
opt_verbose=
50+
opt_steps=()
51+
while (( $# )); do
52+
case "$1" in
53+
fetch|check) opt_steps+=("$1"); shift;;
54+
--config) shift; opt_zuliprc="$1"; shift;;
55+
--verbose) opt_verbose=1; shift;;
56+
--help) usage; exit 0;;
57+
*)
58+
if [ -n "$opt_corpus_dir" ]; then
59+
# Forbid passing mutliple corpus directories.
60+
usage >&2; exit 2
61+
fi
62+
opt_corpus_dir="$1"; shift;;
63+
esac
64+
done
65+
66+
if [ -z "$opt_corpus_dir" ]; then
67+
echo >&2 "Error: Positional argument CORPUS_DIR is required."
68+
echo >&2
69+
usage >&2; exit 2
70+
fi
71+
72+
if (( ! "${#opt_steps[@]} " )); then
73+
opt_steps=( "${default_steps[@]}" )
74+
fi
75+
76+
run_fetch() {
77+
if [ -z "$opt_zuliprc" ]; then
78+
echo >&2 "Error: Option \`--config\` is required for step \`fetch\`."
79+
echo >&2
80+
usage >&2; exit 2
81+
fi
82+
83+
if [ -n "$opt_verbose" ]; then
84+
echo "Fetching all public messages using API config \"$opt_zuliprc\"." \
85+
" This can take a long time."
86+
fi
87+
# This may have a side effect of creating or modifying the corpus
88+
# file named after the Zulip server's host name.
89+
tools/content/fetch_messages.dart --config-file "$opt_zuliprc" \
90+
--corpus-dir "$opt_corpus_dir" \
91+
|| return 1
92+
}
93+
94+
run_check() {
95+
flutter test tools/content/unimplemented_features_test.dart \
96+
--dart-define=corpusDir="$opt_corpus_dir" \
97+
--dart-define=verbose="$opt_verbose" \
98+
|| return 1
99+
}
100+
101+
for step in "${opt_steps[@]}"; do
102+
echo "Running ${step}"
103+
case "${step}" in
104+
fetch) run_fetch ;;
105+
check) run_check ;;
106+
*) echo >&2 "Internal error: unknown step ${step}" ;;
107+
esac
108+
done

tools/content/fetch_messages.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import 'model.dart';
2121
/// Because message IDs are only unique within a single server, the script
2222
/// names corpuses from each server differently (if --corpus-dir is specified).
2323
///
24+
/// This script is meant to be run via `tools/check parser`.
25+
///
26+
/// For more help, run `tools/content/fetch_message.dart --help`.
27+
///
2428
/// See tools/content/unimplemented_features_test.dart for more details.
2529
void main(List<String> args) async {
2630
final argParser = ArgParser();

tools/content/unimplemented_features_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import 'model.dart';
1616
/// Check if there are unimplemented features from the given corpuses of HTML
1717
/// contents from Zulip messages.
1818
///
19-
/// This test is meant to be manually run.
19+
/// This test is meant to be run via `tools/content/check-features`.
2020
///
21-
/// To run it, use:
21+
/// To run it directly, use:
2222
///
2323
/// flutter test tools/content --dart-define=corpusDir=path/to/corpusDir
2424
///

0 commit comments

Comments
 (0)