1491 Commits

Author SHA1 Message Date
Dandelion Mané
eddb92ba5f
cli/load should fail if any plugin fails to load (#1922)
Previously, if any individual plugin failed to load, the load command
would print an error, but return exit code 0.

As of this commit, the load command returns 1 if any plugin(s) fail to
load, and prints the name(s) of the offending plugins.

Test plan: CLI doesn't have automated testing, so induce failure in an
instance by e.g. setting the SOURCECRED_GITHUB_TOKEN="" in an instance
which uses the GitHub plugin.

Observe that the full error message is still printed to console, and
that the command returns exit code 1, and that if more than one plugins
fail that the message is printed nicely showing all the failed plugins.

Also observe that load's behavior on successful loads is unchanged.
2020-07-06 14:00:13 -07:00
Robin van Boven
9dbb25b94b
Discourse: remove unused SQL queries (#1929)
Given the removed recheckTopicsInCategories feature, this removes SQL
queries that are unused.
2020-07-06 12:01:22 -07:00
Robin van Boven
1b7a522f22
Discourse: remove recheckTopicsInCategories feature (#1928)
Previously this recheck had a usecase: give priority to categories
that are used as Initiative source of truth. This model was abandoned
and so the priority doesn't make much sense either.

Instead use cache clearing to guarantee recent data when you need it.
2020-07-06 11:56:01 -07:00
Dandelion Mané
e6c7ac2063
Fixup Username semantics and implementation (#1930)
This commit incorporates post-merge review feedback from @wchargin,
as found in [this review].

[this review]: https://github.com/sourcecred/sourcecred/pull/1915#pullrequestreview-442543321

Test plan: Unit tests updated; `yarn test` passes.
2020-07-05 18:50:22 -07:00
Dandelion Mané
9125676b4e
Fixup update_snapshots.sh (#1927)
This is a leftover from #1904.

Test plan: `./scripts/update_snapshots.sh` now works.
2020-07-05 13:04:43 -07:00
Dandelion Mané
e9c70d5327
Add a ledger/user type (#1915)
This adds a user type to the ledger. Each user is tracked by a UUID, and
has a human-specified and renameable username. Each user also
corresponds to a node in the graph, and has a list of aliase addresses
that should be merged into it using `graph.contractNodes`.

It's important that we track this in the ledger because the ledger needs
to reconcile when aliases are added or removed.

Test plan: Unit tests added. Quite a simple module.
2020-07-05 01:36:21 -07:00
Dandelion Mané
43d378ca93
Remove the recharts dep (#1921)
It was a part of the removed TimelineCred frontend.

Test plan: CI will suffice.
2020-07-04 17:56:20 -07:00
Dandelion Mané
387000dae8
Set version to 0.7.0 (#1919)
As a precursor for the eventual next release.
2020-07-04 16:23:41 -07:00
Dandelion Mané
c08ce1543d
Modify Discord to mint Cred for every emoji (#1918)
This changes the Discord plugin so that, by default, it adds every
Reaction to the graph, so they will all mint Cred.

If custom reaction weights are added, they will act as multiplicative
modifiers on the Cred minting.

Test plan: I've tested this in production, by deploying SourceCred's own
Cred from this patch. The Discord plugin has no unit tests.
2020-07-04 15:12:03 -07:00
Dandelion Mané
26c70764ae
graph: support choosing specific plugins (#1917)
This is the dual to #1858; it allows the cli/graph command to choose to
load only specific plugins.

This is helpful if, for example, you load an instance where you don't
have the credentials to re-load one of the plugins, but want to update
the other plugins. Then you can load and graph the plugins for which you
do have data, but leave the graph for the inaccessible plugin
un-touched.

Test plan: Manual testing, as with #1858 and for similar rationale.
2020-07-03 15:19:32 -07:00
William Chargin
abbc024cbf
util: add uuid module (#1914)
Summary:
A new utility module defines an opaque UUID type. Clients can generate
random UUIDs and convert them to and from strings.

We roll our own module here rather than using the `uuid` NPM module
because that module only exposes the 32-character hyphen-separated
string form of UUID, which takes up nearly 50% more space. The usual
approach these days is to use fixed-length base64 strings without
padding. For instance, [YouTube video IDs are of this form][yt].

This module takes care not to generate IDs that might confuse
command-line argument parsers, and tries not to generate IDs that might
contain English curse words. The implementation uses isomorphic
libraries for RNG and base64 conversion because the relevant Node and
browser APIs are not aligned.

[yt]: https://webapps.stackexchange.com/a/101153

Test Plan:
Unit tests included, with full coverage.

wchargin-branch: util-uuid
2020-07-02 12:29:27 -07:00
Dandelion Mané
ba8313e4b4
Enable score command to load weights (#1913)
Now, if a `weights.json` file is present in the `config/` folder, its
weights will be loaded and used in computing the credResult.

Test plan: We don't yet have proper unit testing for the CLI, so I added
weights to the snapshot. The snapshot weights are pretty silly; 32x for
Discourse posts and 32x for GitHub bots. Load the UI via `yarn start`,
and observe that these weights were persisted in the CredResult.
2020-07-01 11:43:14 -07:00
Dandelion Mané
f0aeb9425e
The score command now supports custom params (#1912)
If the instance wants to specify custom TimelineCredParams, e.g. a
custom alpha value, they may now write a partial TimelineCredParams file
as `config/params.json`.

Test plan: We don't yet have proper unit testing for the CLI, so I added
this case to the test-instance. Using the new frontend, I've verified
that the custom alpha value is correctly reflected in the output data
(use `yarn start`, open weight config, and view alpha).
2020-07-01 11:26:55 -07:00
Dandelion Mané
20b6cd672d
yarn start uses test-instance by default (#1911)
Prior to this commit, `yarn start` would fail if a development instance
path is not provided. However, now that we package a test instance
inside of our snapshots, we can use that as the default dev instance
instead.

Test plan: `yarn start` with no arguments or environment variables now
loads the test instance, both when run from repository root, and when
cd'd into a subdirectory.
2020-07-01 11:11:45 -07:00
Dandelion Mané
c796c6e740
New UI shows weights and recomputes Cred (#1910)
This commit adds a major piece of missing functionality to the new UI:
the ability to view weights, change parameters, and then re-compute
Cred. The code has mostly been copied from the v2 UI.

Test plan: Manual testing around changing weights and params, and
recomputing Cred.
2020-06-30 23:06:00 -07:00
Dandelion Mané
d865681faf
Move explorer/weights to ui/weights (#1909)
Test plan: Just a move/rename, `yarn test` passes.
2020-06-30 22:50:52 -07:00
Dandelion Mané
19572c5bc4
Add support for recomputing credViews (#1908)
This will be needed for letting the UI recompute Cred scores with new
weights / params (which is a vital feature!).

Test plan: Not tested :'( will sanity check via frontend integration.
2020-06-30 22:46:44 -07:00
Dandelion Mané
811bf32968
Move plugin configs to config/plugins (#1907)
This changes the instance system structure so that all the
plugin-specific configs are organized under
`config/plugins/$OWNER/$NAME` instead of `config/$OWNER/$NAME`. I think
this is a somewhat clearer structure; since `config/` will hold other
files (e.g. `weights.json` or `params.json`), I think it's cleaner if
everything plugin-specific is under it's own clearly scoped folder. This
avoids potential confusion if we ever have plugins with very
generic-named organizations, e.g. "config".

Test plan: The test instance has been updated, and the sharness test
loading still works.
2020-06-30 11:24:23 -07:00
William Chargin
7ab3a74c3a
cli: add site subcommand (#1905)
Summary:
The `sourcecred site` command now sets up a static site for a cred
instance, which may be deployed to (e.g.) GitHub Pages or IPFS.

This implementation sets up a directory structure where the site is
contained in a `site/` subdirectory whose top-level entries are also
symbolically linked from the root of the instance. Thus:

```
my-instance/
    sourcecred.json
    config/
    output/
    site/
        index.html
        favicon.png
        static/
            static/js/...
    index.html -> site/index.html
    favicon.png -> site/favicon.png
    static -> site/static
```

The purpose of this is to enable the instance to be served directly as a
GitHub Pages site without the user having to navigate to a URL that
includes a `site/` path component.

It’s not a perfect solution. The top level of the instance is cluttered.
If we have any web pages other than the root directory, then they’ll
appear at top level, too. If we change the structure, we’ll need to
teach `sourcecred site` to clean up vestiges of old structures. We also
won’t be able to have any pages called `config` or `output` or `cache`
due to namespace collision. But we think that it’s at least a reasonable
stopgap, and doesn’t incur much conceptual overhead.

This isn’t tested or officially supported on Windows.

Paired with @decentralion.

Test Plan:
Run `yarn build` to build the frontend and backend, then `cd` into a
SourceCred instance and run `node "${OLDPWD}/bin/sourcecred.js site`.
Note that a `site/` directory is created, and when the static site is
served it works from either `site/` or the instance root. Note that this
all works when actually deployed to GitHub Pages as well.

wchargin-branch: cli-site
2020-06-27 23:21:56 -07:00
William Chargin
a30c45bc05
build: fix references to yarn backend (#1904)
Summary:
Follow-up to #1903. In particular, this should fix the Docker build.

Test Plan:
Running `git grep 'yarn backend'` no longer turns up examples.

wchargin-branch: build-update-yarn-backend-refs
2020-06-27 22:51:10 -07:00
William Chargin
69e945ab23
build: create unified yarn build command (#1903)
Summary:
Previously, we used `backend` to build the backend and `build` to build
the frontend, which was a bit confusing. Now, `build:backend` and
`build:frontend` build the respective components, and `build` builds
both in parallel.

Test Plan:
Run `rm -r bin build` and then `yarn build`, and note that the `bin` and
`build` directories are recreated.

wchargin-branch: build-unified-cmd
2020-06-27 21:16:55 -07:00
William Chargin
652190eb2d
deps: add dev dependency on npm-run-all (#1902)
Summary:
We want this to run the frontend and backend builds in parallel.

wchargin-branch: deps-npm-run-all
2020-06-27 21:11:28 -07:00
Dandelion Mané
7a531560b1
Remove the project type (#1900)
This commit removes the `core/project.js` type. It was a sort of
"kitchen sink" config file where we just threw any random thing. This
was not a good approach to config, so now we let each plugin provide
it's own config format, and we no longer need (or want) the project
type.

I removed a test from the compatIO module, although we'll probably
remove that too ere long.

Test plan: `yarn test`.
2020-06-27 21:04:08 -07:00
Dandelion Mané
86fd5638bb
Add snapshot testing for instances (#1897)
This adds a simple sharness snapshot test for the new instance system,
in the model of the old [test_load_example_github.t][old].

I've setup a very simple test instance with the GitHub and Discourse
plugins, and we verify that the output generated by running `load`,
`graph`, and `score` in succession is stable. (Cache is not
persisted.) This is a nice sanity check to verify that nothing ever gets
totally broken; we'll still want to add unit testing for more specific
features and edge cases.

Test plan:
`yarn test --full` passes.
If you `rm -rf sharness/test-instance/output`, then `yarn test --full`
fails.
If you then run `./scripts/update_snapshots.sh`, then the output
directory will be restored; afterwards `yarn test --full` passes again.

To verify that the snapshots are valid, you can test them with the
frontend:
`yarn start --instance sharness/__snapshots__/test-instance`

If you are actually debugging this script, rather than using
`yarn test --full` you'll want to invoke
`(cd sharness; ./load_test_instance.t -l -v)`

[old]: https://github.com/sourcecred/sourcecred/blob/v0.6.0/sharness/test_load_example_github.t
2020-06-27 20:41:49 -07:00
Dandelion Mané
46c8e83d28
Remove vestigial load-related logic (#1898)
This commit removes old logic related to loading projects in the context
of "data directories". In particular, almost all of the `src/backend`
directory is removed (and I suspect the remaining files should come out
too; definitely the compat_io module is superseded by the new Parser
based approach). The old style loaders are also removed, as they are
rendered redundant by the new CliPlugin interface.

Test plan: `yarn flow` passes, and none of the load-bearing (ha ha)
parts of the current setup are impacted, i.e. there are no changes to
the CLI. Thus, we may be confident that everything is still working.
2020-06-27 20:30:44 -07:00
Dandelion Mané
f6dbbc951f
Remove legacy explorer UIs (#1899)
This commit removes (both) legacy explorer UIs, since they have been
replaced as of #1894.

Test plan: No code that is currently in use has been touched, `yarn test`
passes. Clean deletes are easy.
2020-06-26 14:03:44 -07:00
Dandelion Mané
219c4490b2
Add parser for TimelineCredParams (#1895)
This will allow us to integrate with the `scores` module in a way that
has runtime validation of the config.

Test plan: See included tests.
2020-06-25 19:39:44 -07:00
Dandelion Mané
dcb7219cb8
Add a new Explorer UI for instanced cred (#1894)
This commit integrates a new version of the cred explorer, which is
compatible with the new instance-based cred. It combines some of the
benefits of the v1 explorer (shows cred source decomposition) and the v2
explorer (shows cred-over-time for users). It's still very basic, and it
lacks an important feature of both v1 and v2 in that it doesn't allow
recomputing cred scores with new weights.

Nonetheless, it's a big improvement over having no functional ui at all!

Test plan: Manually test with a real instance, e.g. via
`yarn start --instance $PATH`
2020-06-25 16:22:39 -07:00
Dandelion Mané
26cf0af7f7
CredView provides node and edge types (#1893)
This is a convenience for frontend development.
Not tested because this module is rotten.

Test plan: Has been used successfully in downstream commits.
2020-06-25 14:51:06 -07:00
Dandelion Mané
1fc0a39cef
Add CredView.userNodes (#1892)
It's a simple yet helpful method. It's not tested because this module is
rotten.

Test plan: It's been successfully used in downstream commits.
2020-06-25 14:47:30 -07:00
Dandelion Mané
b170ff6cc2
CredView computes inFlows and outFlows (#1891)
This adds `inflows` and `outflows` methods to the CredView.

The CredView module is known-temporary because it is built on top of
TimelineCred, which is going to be replaced by CredRank. Also, it's
extremely hard to write proper tests for, because TimelineCred is rotten
and doesn't have clearly defined semantics on small, easily tested
graphs.

Therefore, I haven't written unit tests for this; I have already used it
in downstream UIs and it does show consistent and intuitive results, so
I am reasonably confident that it works.

I expect this will stay in the codebase for 1-3 months before being
replaced by new (and thoroughly tested) views built over CredRank's
output data.

Test plan: Downstream usage in commits, e.g. see UI in:
9b9ec4bf1d
2020-06-25 14:33:10 -07:00
William Chargin
160de95e9f
compat: expose type for JsonObject compatibility (#1886)
Summary:
By making the `Compatible<T>` type definition transparent, it becomes
valid to pass a compat value to the `parse` or `parseOrThrow` method of
a `Combo.Parser`. Ideally, we’d be able to more precisely specify the
relationship (`instance Json t => Json (Compatible t)`), or failing that
at least uniformly require that `T: JsonObject` and keep the type
definition opaque, but the former isn’t possible in Flow and the latter
is [blocked on a Flow bug][1], so this will have to do for now.

Fixes #1875.

[1]: https://github.com/facebook/flow/issues/8405

Test Plan:
Running `git grep 1875` no longer turns up anything relevant.

wchargin-branch: compat-expose-jsonobject
2020-06-22 10:46:34 -07:00
William Chargin
fb669962a0
combo: make JsonObject arrays/objects covariant (#1885)
Summary:
This is more general: a mutable type is a subtype of its corresponding
read-only type. Using the covariant form lets structures like `string[]`
be subtypes of `JsonObject`, as `T[]` is not (in general) a subtype of
`(T | U)[]` but is a subtype of `$ReadOnlyArray<T | U>`.

Test Plan:
Demonstration type-level tests added.

wchargin-branch: jsonobject-readonly
2020-06-22 10:42:36 -07:00
Dandelion Mané
ad6656d53e
Make cli2 report the version and provide help (#1887)
We need the `--version` flag, both for general goodness, and because our
Docker publish pipeline depends on it. While I was at it, I
re-integrated the `help` command as well, along with some unit testing.

Test plan: `yarn test` passes; run `yarn backend` and then run the
command both without args (to see a dummy help message), or with the
`--help` or `help` args, or with `--version` args. Unit tests cover all
thsi behavior.
2020-06-21 23:28:06 -07:00
Dandelion Mané
d736cd4d2e
Rename cli2 to cli (#1884)
This moves all of the `cli2` command files into the `cli` directory,
since we are making the instance CLI the canonical CLI.

Test plan:
`yarn test --full` passes; `git grep cli2` returns no hits.
2020-06-21 23:19:39 -07:00
Dandelion Mané
609d07e04c
Remove old CLI (#1883)
This commit removes the old CLI, which is being replaced by the new
instance-system based approach (currently called cli2).

This also removes sharness tests on the old CLI, as well as the
associated snapshots. This is a little unfortunate since the GitHub
snapshot did provide some validation against changes to the plugin; we'd
do well to re-integrate such a system when adding testing to cli2.

Test plan: `yarn test --full` passes. Since this is just a removal,
there's not much that can go wrong.
2020-06-21 21:41:35 -07:00
William Chargin
222f4a0738
deps: upgrade flow-bin@^0.127.0 (#1881)
Summary:
One weird hack needs to be slightly amended; everything else still works
given recent changes to suppression comments.

Test Plan:
Running `yarn flow` passes as is, but fails if a suppression comment is
removed.

wchargin-branch: flow-v0.127.0
2020-06-21 21:39:32 -07:00
William Chargin
61d6d22c2f
flow: rename $ExpectFlowError to $FlowExpectedError (#1880)
Summary:
The latest versions of Flow restrict suppression comments to the fixed
names `$FlowExpectedError` or `$FlowFixMe`. This patch replaces uses of
our custom suppression comment with `$FlowExpectedError`, as we don’t
use suppressions to mean “fix me; need to add types later” but instead
as expected type errors in tests (almost exclusively).

Generated by changing the suppression in `.flowconfig` and then running:

```
git ls-files -z '*.js' |
    xargs -0 sed -i -e 's/\$ExpectFlowError/$FlowExpectedError/g'
```

To check the changes in non-test files, run

```
git show ':!*.test.js'
```

and note that all changes are in fact expected errors rather than TODOs.

Test Plan:
Check that `yarn flow` passes as is, but fails if a `$FlowExpectedError`
comment is deleted.

wchargin-branch: flow-standard-suppressions
2020-06-21 21:32:08 -07:00
William Chargin
deb257ff6a
flow: update libdefs for express, removing hacks (#1879)
Summary:
This removes a SourceCred-specific hack because the upstream issue has
been fixed. Removing the hack is important because it uses a suppression
comment and thus hampers upgrading to latest Flow.

The libdef portion of this change was generated by removing the old file
and then running `flow-typed install express@4.17.1`.

Test Plan:
That `yarn flow` passes suffices.

wchargin-branch: libdefs-express
2020-06-21 21:25:24 -07:00
Dandelion Mané
e744b2bd4a
Remove build2 / start2 references (#1882)
Now that we're making the new UI the canonical one, we can remove
references to calling it `build2` or `start2`.

Test plan: `yarn start --instance $PATH` and `yarn build` both work.
`yarn test --full` passes.
2020-06-21 21:17:25 -07:00
Dandelion Mané
84c9122a2a
Kill the old homepage (#1874)
This commit removes the old homepage entirely. This is a prelude
to removing the react-router dependency, which is needed to unblock work
on the initiatives editor.

Because the homepage is gone, there's now no frontend included with
SourceCred. As such, we should merge #1873 alongside this one, so that
our README doesn't give any patently false information to our users.

Test plan: `yarn test` passes. `yarn start` and `yarn build` are no
longer commands. (`yarn start2` and `yarn build2` will be renamed
later).
2020-06-21 20:58:49 -07:00
Dandelion Mané
f9d62188e4
Add parser for core.Weights (#1877)
This adds a proper parse for core.Weights, and modifies the `fromJSON`
method to use that parser.

This means we now have runtime validation that all Weights files are
actually valid.

Note: I made a tweak to the eslint config so as to allow `_`s in names
when followed by a sequence of numbers, so that types like `Data_0_1_0`
(for including version strings) do not trigger lint failures.

Test plan: All existing tests pass, and I added a new test to validate
that we keep supporting the 0.2.0 format going forward.
2020-06-21 20:58:42 -07:00
Dandelion Mané
6f9719d8ba
Remove instructions from README (#1873)
Our README.md has a hodge-podge of information about using SourceCred.
Much of it is about to go entirely out of date because we are killing
the old CLI and frontend.

As such, I'm cleaning out and greatly simplifying the README, so we
won't give our users inaccurate information. I didn't make an effort at
replacing the documentation, that will come afterwards once we're ready
to document the instance system.
2020-06-21 20:54:57 -07:00
Dandelion Mané
cbfa6ed648
Document compatible type issue (#1876)
See #1875 for details.
2020-06-19 13:47:25 -07:00
Brian Litwin
7797c120e6
Discord: add Mirror class (#1780)
Creates a class to handle the implementation
of fetching data from the Discord server and
saving it to the local mirror.

Test plan:

Unit tests added.

paired with @beanow
2020-06-19 11:54:08 -07:00
Dandelion Mané
ea175a390a
Add Address.fromRaw (#1871)
This adds a fromRaw method to the Address module so that we may properly
parse serialized addresses. It has a type signature of `string =>
Address`, and throws an error if the string is not a valid address.

I basically copied the implementation out of the `assertValid` method. I
considered deduplicating them (i.e. having `assertValid` simply call
`fromRaw`), but `assertValid` had some extra logic around accepting a
prefix for the error message, and it felt simpler to simply copy+paste
rather than trying to wrap it.

Test plan:
I added unit tests; `yarn test` passes.
2020-06-19 11:20:02 -07:00
William Chargin
8ea16de6f9
combo: accept a key parser in dict (#1872)
Summary:
An optional second parameter to `C.dict` can now be used to refine keys
to a subtype of string: e.g.,

    C.dict(C.number, C.fmap(C.string, NodeAddress.fromRaw))

is a `C.Parser<{[NodeAddressT]: number}>`. Before this change, `C.dict`
could only parse objects whose key type ranged literally over `string`.

Note that the argument order is `C.dict(valueParser, keyParser)`, not
the other way around. This is because `C.dict(valueParser)` is the more
general use case (you _need_ a value parser), and it’s simpler to have
the optional argument be at the end. (Analogously, the `forEach` methods
on `Array`s and `Map`s take a callback accepting `(value, key)`.)

Test Plan:
Unit tests included, retaining full coverage. Existing tests for the
experimental Discord plugin, which uses `C.dict`, also still pass.

wchargin-branch: combo-dict-key
2020-06-18 20:35:26 -07:00
Dandelion Mané
bca825b535
cli2 common: add util to load json files (#1868)
This adds two methods to cli2/common.js:
- loadJson, which loads a JSON file from disk and then parses it
- loadJsonWithDefault, which loads a JSON file from disk and parses it,
  or returns a default value if the file is not present.

Both methods are well documented and well tested.

Test plan: `yarn test`; see included unit tests which are thorough.
2020-06-17 22:53:17 -07:00
Dandelion Mané
a8f353b33f
add support for parsing compatible objects (#1867)
This adds Combo parsing support to the compatible module. Now, rather
than writing `fromJSON` methods which implicitly take any, we can
instead write typesafe `parseJSON` methods which will parse compatible
headers, and then choose a version-appropriate parser.

Test plan: Added unit tests; `yarn test` passes.
2020-06-17 20:36:38 -07:00
Dandelion Mané
67b74d7cfe Rename homepage2 to ui
Just a more sensible name since it's not a homepage of any sort.

Test plan: Flow passes, `yarn build2` and `yarn start2` both succeed.
Also: `git grep homepage2` gets no hits.
2020-06-17 20:02:35 -07:00