Skip to content

Commit f2fa4a8

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 an 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. For the most part, we intend to only keep the detailed explanations in the underlying scripts close to the implementation, and selectively repeat some of the helpful information in the wrapper. This also repeats some easy checks for options, so that we can produce nicer error messages for some common errors (like missing zuliprc for `fetch`). Fixes: zulip#190
1 parent 1e39bc8 commit f2fa4a8

File tree

3 files changed

+112
-2
lines changed

3 files changed

+112
-2
lines changed

tools/content/check-features

+108
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 required. It is the directory to store or read corpus files
17+
which will be created 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

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ 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/content/check-features`.
25+
///
2426
/// For more help, run `tools/content/fetch_message.dart --help`.
2527
///
2628
/// See also:

tools/content/unimplemented_features_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import 'model.dart';
1717
/// Check if there are unimplemented features from the given corpuses of HTML
1818
/// contents from Zulip messages.
1919
///
20-
/// This test is meant to be manually run.
20+
/// This test is meant to be run via `tools/content/check-features`.
2121
///
22-
/// To run it, use:
22+
/// To run it directly, use:
2323
///
2424
/// flutter test tools/content --dart-define=corpusDir=path/to/corpusDir
2525
///

0 commit comments

Comments
 (0)