Commit Graph

1438 Commits

Author SHA1 Message Date
Dandelion Mané e6a3d776ab
Configure fe2 to load from instances (#1856)
This modifies the frontend2 so that we can load real data from cli2
instances, including:
- the root `sourcecred.json` config
- files inside the `config/` directory
- files inside the `output/` directory

This works both for the dev server and the compiled output.

In the case of the dev server, it's now necessary to provide the path to
the cli2 instance you're developing against. You can pass this via the
`--instance` argument, as in `yarn start2 --instance=/path/`, or via
the `$SOURCECRED_DEV_INSTANCE` environment variable (recommended). If
neither is provided, or if that path doesn't look like a valid instance,
an error is thrown.

In the case of the built output, given a valid sc2 instance, you can set
it up via the following:

```
cp -r build2/favicon.png build2/index.html build2/static $INSTANCE
```

Then spin up a simple http server in the $INSTANCE.

You can look at console messages in the frontend to verify that the
instance is working (note it expects to see a discourse config file, not
a GitHub config file as was used in some previous examples).

Test plan:
Setup an example Discourse instance, and then turn on the server via
`yarn start2 --instance=PATH`,
`SOURCECRED_DEV_INSTANCE=path yarn start2`,
and by manually copying in the built outputs using the instructions
above.

In each case, you can load the homepage and check the console to see
that assets loaded successfully.
2020-06-17 18:47:12 -07:00
Dandelion Mané cb637dbaa4
Frontend2: Remove references to projectIds (#1855)
The frontend build system has a bunch of logic for loading in the list
of projectIds and including them in the build. Fortunately, in
frontend2, we won't need this. This commit simply removes all that
logic.

Test plan: Grepping for `projectIds` finds no hits inside the frontend2
system, except for a comment noting that we'll be able to remove an
argument once the transition is complete. `yarn start2` still works as
expected.
2020-06-17 18:45:50 -07:00
Dandelion Mané 4b0fcb96be
Radially simplify homepage2 (#1854)
This drastically streamlines the new frontend entry directory.
All the logos, the nav bar, the pages, etc, are all gone.
Now there's just a landing page that reads "Under Construction".

Test plan: Run `yarn start2`, observe that there's just an empty landing
page that we'll rebuild from.
2020-06-17 18:45:16 -07:00
Dandelion Mané f25bc795c6
Fork the frontend to build towards cli2 compat (#1853)
The cli2 ("instance") system has a foundationally different assumption
about how the frontend works: rather than having a unified frontend that
abstracts over many separate SourceCred projects, we'll have a single
frontend entry per instance. This means we no longer need (for example)
to make project IDs available at build time.

Our frontend setup and server side rendering is pretty complex, so
rather than rebuild it from scratch, I'm going to fork it into an
independent copy and then change it to suit our needs.

To start here, I've duplicated the `src/homepage` directory into
`src/homepage2`, duplicated the webpack config to
`config/webpack.config.web2.js`, and duplicated the paths and
package.json scripts.

Test plan:
Run `yarn start2` and it will start an identical frontend, using the
duplicated directory. Run `yarn build2` and it will build a viable
frontend into the `build2` directory. `build2` is gitignored.
2020-06-17 18:44:34 -07:00
Dandelion Mané 53d3bd6766
Combine the `merge` and `score` commands (#1859)
As discussed [in Discord]:

At present, cli2 is organized around the following commands:

- init: help setting up a new SourceCred instance (not yet implemented)
- load [PLUGINS...]: load data from all active plugins (default) or
specific named plugins
- graph: regenerate graph for every plugin (will likely give this
[PLUGINS...] args in the future)
- merge: merge the generated graphs together
- score: compute scores over all the graphs

I'm going to change this to fold the merge command into the score
command. This is inspired by realizing that setting the weights.json
should get incorporated in the merge command from an implementation
perspective, but in the score command conceptually.

Thus, having merge and score as separate commands is actually an
anti-affordance, it allows the user to get into a confusing state where
the graph in their output directory is in a different state from the
scores.

(also, merge takes about 2s on sc's cred instance, so it isn't a huge
performance penalty on the flow of "recompute scores with new
parameters")

cc @wchargin

Also, I wonder whether we should persist the weightedGraph to disk at
all, seeing as it is already included in the credResult.json.

Storing the graph on its own is inefficient from a space perspective,
although it can be nice to get an eyeball sense of how big the
graph is compared to the associated cred data. For now, I'm not going to
write the weightedGraph to disk, simply because it's more convenient to
implement.

If there's a need, we can add it back later.

[in Discord]: https://discordapp.com/channels/453243919774253079/454007907663740939/721603543278157905

Test plan: manually tested it on a local instance
2020-06-15 12:40:45 -07:00
Dandelion Mané e49823921d
cli2 load: support loading specific plugins (#1858)
This modifies cli2/load so that you can now provide a list of fully
scoped plugin names (e.g. sourcecred/github) and it will load only the
mentioned plugins. If any plugins aren't available, an error is thrown.
If no plugins are listed, all of the activated plugins are loaded.

Test plan: Tested locally in success and failure cases. No unit tests
atm, which matches the rest of cli2--tbh this feels like the kind of
code where the liklihood of subtle failures or regressions is low, and
it's a pain to test, so I'm content with the status quo for now.
2020-06-13 19:46:43 -07:00
Dandelion Mané dd76595ac2 Setup Discord cli2 plugin
This adds a cliPlugin to the experimental Discord plugin, along the
lines of the cli 2 plugins for GitHub and Discourse.

Test plan: I set up a Cred instance for SourceCred including our Discord
config, and successfully loaded Cred for it. Not easy to give full
reproduction instructions, not least because it requires a private
Discord bot token.
2020-06-13 12:27:46 -07:00
Dandelion Mané 6e6d749902 Discord: Add config parsing
I also documented how to fill out the config.

Test plan: Sanity unit test included, `yarn test` passes.
2020-06-13 12:27:46 -07:00
Dandelion Mané b31d9e6ac1 Rename discord/params to discord/config
Just doing this for consistency with the other plugins.

Test plan: Simple rename-refactor, `yarn flow` passes.
2020-06-13 12:27:46 -07:00
Aaron Foster 8ca7840187
readme: fix minor spelling error (#1852) 2020-06-12 09:59:22 -07:00
Dandelion Mané 8436dcee81
Add nodes and edges to CredView (#1839)
This adds support for retrieving cred-augmented nodes and edges to the
CredView class. These methods wrap the underlying Graph methods, and
return nodes and edges that also include relevant cred information

Test plan: Unit tests included; yarn test passes.
2020-06-09 16:40:03 -07:00
Dandelion Mané 753aec3acf
Start the CredView class (#1838)
This commit adds the CredView class, an interface for Graph-aware
queries over a CredResult. To start, I just added accessor methods for
reaching the constituent data in the CredResult.

Test plan: `yarn test`
2020-06-09 16:37:03 -07:00
Dandelion Mané 61224340f4
Re-rasterize the png logos (#1849)
In #1738, @wchargin updated the svg logo with a cleaner path structure.
This commit re-runs the rasterize script with the new svg, which
results in much cleaner pngs without aliasing.

Test plan: The new pngs look a lot cleaner.
2020-06-09 12:00:58 -07:00
William Chargin e91a2ae247
Treat Sharness snapshots as binary (#1846)
Summary:
The Sharness snapshots contain large data files that are effectively
blobs, but happen to be encoded as UTF-8 JSON. Consequently, they fill
up a terminal with junk when they wriggle into a `grep` or `diff` or
similar. This patch fixes that by teaching Git to treat them as binary.
If you ever want to see a raw diff (unlikely, since these files have
many kilobytes of data with no newlines), just pass `-a`/`--text`.

This isn’t perfect—e.g., it only works with Git (not, e.g., Ripgrep)—but
it’s better than nothing.

Test Plan:
Run `git grep 6961` and note that the result now shows just three lines,
including the desired text result and two “Binary file matches” notes.
Run `git grep -a 6961` and note that the monstrosity returns.

wchargin-branch: sharness-snapshots-binary
2020-06-08 09:43:51 -07:00
Hammad Jutt bf64e4b1c5
Prevent overriding project fields when auto-upgrading (#1847)
If a project.json file defines a field that belongs to a newer version but the compat version wasnt updated, the
auto-upgrade code would silently throw away the field, changing it to the default setting of null. This fixes it
by spreading the project object after adding the new field instead of before, that way if that field was defined
in the project file it wont get overwritten while still adding the empty case if it wasnt defined.

Test Plan: Add a field belonging to ProjectV052 in a project file with compat version 0.5.0 and ensure it doesn't get
overwritten.
2020-06-08 00:30:43 -07:00
Dandelion Mané 87dd43d057
Add alias support for experimental discord (#1848)
This updates the alias "plugin" to support the experimental Discord
plugin that we recently merged into master. Without this, we can't
resolve Discord aliases.

Test plan: Validated on SourceCred's own cred instance. No unit tests
added since both modules in question (experimental discord and alias)
are going to be replaced or re-written, and the experimental-discord
plugin has no testing at all.
2020-06-08 00:19:54 -07:00
Hammad Jutt a38860a3d2
Move Experimental Discord plugin into master (#1843)
Since the discord branch is being used in production by many projects (MetaGame, AraCred, RaidGuild, etc), and we also want to start using it for SourceCred, it would be a good idea to merge it into master in a separate experimental-discord plugin so the proper discord plugin can be developed in parallel while allowing the other projects to stay up to date with master.

paired with @decentralion
2020-06-08 00:00:25 -07:00
Hammad Jutt 1abed5f0ed
Add params field to Project type (#1801)
* Add params field to Project type

This will allow SourceCred instances to override the default alpha and interval decay parameters by adding an optional "params" field in their project.json file. If they don't include any of the fields, it will just fallback to use the default params.

Test Plan: Add params field in project.json file and see if the resulting SourceCred instance correctly picks up the custom alpha value.

* Rename params field in project to timelineCredParams

Makes the field more descriptive and allows it to be nullable

Test Plan: Ensure all usages of Project type are updated to use timelineCredParams field instead of params

* Update Snapshots

Update snapshots for new project version file

Test Plan: Ensure sharness tests pass in CI
2020-06-04 17:23:06 -07:00
VictorGinelli a8a83c4a86
Add dependabot to list of github bots (#1837)
* Add dependabot

* Prettier
2020-06-03 09:47:30 -07:00
Dandelion Mané 2fd32dd785
Use the new lossy cred compression strategy (#1834)
This commit puts the lossy cred compression strategy from #1832 into
production.

When run on the MakerDAO forums, this drops the output size from 41MB
(close to the point where GitHub starts warning about file sizes) to
14MB (plenty of room to grow).

Test plan: I ran it on a local sc2 instance. Unlikely that this
introduced any subtle bugs.
2020-06-01 18:37:58 -07:00
Dandelion Mané d556776cca
Add lossy cred compression strategy (#1832)
This adds a new `compressByThreshold` method in the credResult module,
which compresses the CredResult by removing interval-level cred data for
flows of cred that are below a threshold.

Test plan: Unit tests included; `yarn test` passes.
2020-06-01 18:29:30 -07:00
Dandelion Mané f615ec89a3
cli2 writes CredResult as cred.json (#1833)
This commit modifies the cli2 score command so that instead of writing
the output format described in #1773, it instead writes the new
CredResult format added in #1830. This is a much better engineered
format, and will be useful for building a new frontend as well as for
analysis by third parties (although we will need to provide client code
for parsing it).

Test plan: On a cli2 instance, run `sc2 score` and inspect the resulting
cred.json file.
2020-06-01 18:04:47 -07:00
Dandelion Mané cb1d612f1f
Add the CredResult module (#1830)
This module has a concise and clean type for storing all the output data
from running SourceCred, including:
- The graph
- The weights
- The cred scores and flows
- The interval timing info
- The plugins used
- The parameters used

We also have a method `compute` which computes one of these given the
weighted graph, parameters, and plugins. It's all quite clean and
simple. I feel good about thsi API.

Test plan:
The main `compute` function is only sanity checked via flow and unit
testing, which is appropriate since it's a pure-piping function with
little than can go wrong. I've also added JSON serialization; this is
tested with round trip testing.
2020-06-01 17:47:20 -07:00
Dandelion Mané c5c9f950d4
Compute CredData from TimelineCredScores (#1831)
This commit adds the `analysis/credData` module, which processes raw
TimelineCredScores into a format which is better for serialization and
data analysis. In particular, this format explicitly stores the summary
(summed-across-time) data for nodes separately from the raw temporal
data, which will allow us to throw away raw data for uninteresting or
low-cred nodes, while keeping the summary.

Test plan: I've added some basic unit tests; run `yarn test`.
2020-06-01 17:14:26 -07:00
William Chargin ae181c2fda
combo: add `exactly` combinator for fixed values (#1829)
Summary:
Write `C.exactly(["red", "green", "blue"])` to admit any of a fixed set
of primitive values. This can already be implemented in terms of `raw`
and `fmap`, but it’s more convenient to have a dedicated helper.

Test Plan:
Unit tests included, retaining full coverage.

wchargin-branch: combo-exactly
2020-05-31 22:33:27 -07:00
William Chargin ee0beaf1f1
combo: add backtracking `orElse` combinator (#1828)
Summary:
The `orElse` combinator tries parsing the input with a each of a
sequence of parsers, taking the first successful match (if any). It’s
handy for parsing union types; see examples in the patch.

This combinator treats all errors as recoverable. For instance, a parser

```javascript
C.orElse([
  C.object({type: "NUMBER", number: C.number}),
  C.object({type: "STRING", string: C.string}),
  C.object({type: "BOOLEAN", boolean: C.boolean}),
]);
```

on input `{type: "NUMBER", number: "wat"}` will see that the first
parser fails and try all the others, even though we can see that as soon
as any of these parsers matches the `type` field, we can commit to that
parser rather than backtracking on failure. In a pathological case, even
a small parser can run very slowly and generate very long errors:

```javascript
    it("big", () => {
      let p = C.null_;
      for (let i = 0; i < 12; i++) {
        p = C.orElse([p, p]); // exponential in loop iteration count
      }
      const result = p.parse("non-null!");
      if (result.ok) throw new Error("unreachable");
      expect(result.err.length).toEqual(22558015);
    });
```

Hopefully, this won’t be a problem in practice.

Test Plan:
Unit tests included, retaining full coverage.

wchargin-branch: combo-orelse
2020-05-31 22:29:38 -07:00
William Chargin 0dae2346fc
combo: add `raw` identity parser (#1827)
Summary:
If you want to parse an arbitrary JSON object, or if you want to parse a
complicated dynamic type that can’t easily be expressed in terms of the
other base parsers and combinators, use `C.raw`. This combinator accepts
any input and returns it as a `JsonObject`—not an `any`, so it’s still
safely typed, but the client (either an `fmap` transform or the consumer
of the eventual `parse`/`parseOrThrow`) will need to destructure it by
pattern matching on the `JsonObject` structure.

Test Plan:
Unit tests included (though full coverage technically doesn’t require
them).

wchargin-branch: combo-raw
2020-05-31 22:24:17 -07:00
William Chargin 500140d292
combo: add `dict` combinator (#1826)
Summary:
This is for homogeneous object types with unbounded key sets: roughly,
`dict` is to `object` as `array` is to `tuple`. Its implementation
requires no terrifying type magic whatsoever.

Test Plan:
Unit tests included, retaining full coverage.

wchargin-branch: combo-dict
2020-05-31 22:21:10 -07:00
William Chargin 205f6e064c
combo: add `tuple` combinator (#1825)
Summary:
This new combinator parses heterogeneous tuples: arrays of fixed length,
which may have different, fixed types at each index. For example:

```javascript
type CompactDistribution = [NodeAddressT, number][];
function compactDistributionParser(): C.Parser<CompactDistribution> {
  return C.array(
    C.tuple([
      C.fmap(C.array(C.string), NodeAddress.fromParts),
      C.number,
    ])
  );
}
```

Or:

```javascript
function compatParser<T>(underlying: C.Parser<T>): C.Parser<Compatible<T>> {
  return C.tuple([
    C.object({type: C.string, version: C.string}),
    underlying,
  ]);
}
```

Test Plan:
Unit tests included, retaining full coverage.

wchargin-branch: combo-tuple
2020-05-31 22:17:54 -07:00
William Chargin 64169da128
discourse: use parser combinators for config (#1824)
Summary:
This patch changes the Discourse plugin’s config parsing to use the
parser combinator approach, which simplifies it and removes the need for
all the tests.

Test Plan:
Prior to deleting the tests, they passed, except for the test that
mirror options could not be partially populated; the partial parsing now
works correctly.

wchargin-branch: discourse-config-combinator
2020-05-31 21:52:05 -07:00
William Chargin 930ac715fa
combo: add `shape` helper utility (#1823)
Summary:
Users may now write `C.shape(fields)` instead of `C.object({}, fields)`.

Test Plan:
Unit tests included.

wchargin-branch: combo-shape
2020-05-31 21:48:23 -07:00
Dandelion Mané 4635b46d1f
distributionToCred propagates cred flow data (#1822)
This commit modifies the distributionToCred module so that in addition
to normalizing the scores into cred, it also normalizes the score flows
(from #1802) into cred flows. This is another big part of #1773, so that
we can support the `OutputEdge` format and give meaningful info on cred
flows for each edge.

The change is quite simple, as we already compute a normalization
constant, we just need to apply it to a few more arrays.

Test plan: I added a new unit test that has values in all of the
different flows, so we can validate that they are normalized
consistently.
2020-05-30 16:44:07 -07:00
William Chargin 109ebb0417
combo: convert instance and GitHub configs (#1820)
Summary:
This patch converts the `instanceConfig` and `github/config` parsers
from hand-written traversals to combinator-based structures. The
resulting code is much simpler and easier to read.

Test Plan:
Running the `sc2` CLI for `load` and `graph` still works in the happy
path, with the expected errors if keys in the config files are changed
to the wrong strings.

wchargin-branch: combo-instance-github
2020-05-30 16:04:04 -07:00
William Chargin 272af9db38
combo: allow field renaming (#1819)
Summary:
This patch expands the API of `Combo.object` such that fields in the
input JSON may be renamed in the output JSON. This often occurs in
combination with `fmap`, as we convert a simple string field with a
user-facing name to a different structured representation. For example:

```javascript
C.object({
  repoIds: C.rename(
    "repositories",
    C.fmap(C.array(C.string), repoIdToString)
  ),
});
```

This is backward-compatible and invisible when not needed: the fields of
the argument to `C.object` may now be either parsers (as before) or
results of `C.rename`.

This patch also adds a check that the required and optional key sets
don’t overlap, which could technically have happened before but is more
important now that renames are possible.

Test Plan:
Unit tests included, retaining full coverage.

wchargin-branch: combo-rename-fields
2020-05-30 15:58:05 -07:00
William Chargin ce578ef84c
combo: support heterogeneous objects (structs) (#1818)
Summary:
This combinator is critical to parsing real-world types, which almost
always contain objects at some level. This combinator supports objects
with both required keys and optional keys, as is often needed for
parsing config files and the like.

There’s a bit of dark Flow magic here. In particular, I’ve found that
using a phantom datum in the parser type is necessary for Flow to
correctly extract the output type of a parser without collapsing
discriminated unions. I also ran into some bugs with `$Shape`, which are
avoided by using `$Rest<_, {}>` instead, per this helpful user comment:
<https://github.com/facebook/flow/issues/7566#issuecomment-526324094>
Finally, Flow’s greedy inference for multiple-arity functions causes it
to infer and propagate an empty type in some cases, so we type `object`
as an intersection of functions, or, equivalently, an interface with
multiple callable signatures; this is a trick borrowed from the standard
library for functions like `filter`.

Critically, the tests for this module include tests for expected Flow
errors, so we should be reasonably safe against regressions here.

Test Plan:
Unit tests included, retaining full coverage.

wchargin-branch: combo-object
2020-05-30 15:55:00 -07:00
William Chargin c5bdfcd174
combo: add `pure` and `fmap` combinators (#1817)
Summary:
These are commonly used for building large parsers from small pieces,
especially `fmap`, which is instrumental for transformation and
validation. We pick the name `fmap` rather than `map` to avoid confusion
with ES6 `Map` values, which are unrelated.

Test Plan:
Unit tests and type-checking tests included, with full coverage.

wchargin-branch: combo-pure-fmap
2020-05-30 15:51:08 -07:00
William Chargin 297c4e9156
combo: begin simple parser combinator library (#1816)
Summary:
We often want to parse data from JSON files on disk into similar object
structures in memory. But `JSON.parse` is untyped both statically and
dynamically: it has type `(string) => any`, and it’s happy to accept
structures that aren’t in the shape that you expected. Whenever we write
something like `const c: MyConfig = JSON.parse(raw)` where `raw` comes
from a user-editable file on disk, we’re introducing a trivial soundness
hole. Furthermore, we often want to use a different in-memory state from
the serialized form: perhaps we use ES6 `Map`s in memory, or perhaps
we’ve refined a raw string type to an opaque validated type like
`RepoId` or `NodeAddressT`. These can be done by manually walking the
output of `JSON.parse`, but it’s not pretty: see `instanceConfig.js` or
`github/config.js`.

Parser combinators are a solution to this problem that enable building
parsers for simple primitives and composing them to form parsers for
larger structures. This patch introduces the skeleton of a parser
combinator library, supporting JSON primitives and arrays (but not
objects) along with tests that show its usage. Support for heterogeneous
object (“struct”) types will come in a subsequent patch because the
typing implementation is more complicated, though the interface to
clients is just as simple.

For comparison, this is essentially the `FromJSON` half of the Haskell
library [Aeson][aeson].

It’s possible that we’ll want to generalize this to a broader system of
profunctor optics, maybe over monad transformers, which would make it
easier to both parse and serialize these structures (using “isos” rather
than just parsers everywhere). But manually serializing the structures
is easier than manually parsing them, because they start out strongly
typed. The profunctor generalization is more complicated, and in the
meantime this solves a useful problem, so let’s defer the generality
until we decide that we need it.

[aeson]: https://hackage.haskell.org/package/aeson

Test Plan:
Unit tests included, with full coverage.

wchargin-branch: combo-init
2020-05-30 15:43:11 -07:00
Dandelion Mané 40426f353c
Implement bare-bones sc2 merge and score (#1815)
This adds the missing `merge` and `score` commands to the sc2 CLI.
`merge` currently just merges the plugin graphs, and doesn't yet support
identity resolution or weight overrides.

`score` computes the new data output format (cf #1773) and writes it to
disk. It doesn't yet support using custom parameters.

Test plan:
Follow the test plans for the previous commits, then run `sc2 merge`.
It will create a combined graph at `output/graph.json`, which will
contain data for both Discourse and GitHub. Then run `sc2 score` and
the `output/cred.json` file will contain scores for the combined
graph.
2020-05-30 15:26:01 -07:00
William Chargin c2510d0c1d
cli2: exit on invalid subcommand invocation (#1821)
Summary:
We’d written `die("usage: ...")`, but forgotten to actually return.

Test Plan:
After patching a test instance’s `sourcecred.json` to be invalid,
running `sc2 load extra-arg` now only prints a usage message rather than
an invalid configuration message.

wchargin-branch: cli2-actually-die
2020-05-30 15:20:13 -07:00
Dandelion Mané 7a9d04bc60
cli2: add Discourse CLI plugin (#1814)
This updates the v2 CLI so that it now supports the Discourse plugin.

Test plan:

Modify the test instance described in the previous commits so that the
root `sourcecred.json` file includes "sourcecred/discourse" in the list
of bundled plugins. Then, add a
`config/sourcecred/discourse/config.json` file with the following
contents:
`{"serverUrl": "https://sourcecred-test.discourse.group/"}`

Now, running `sc2 load` will load Discourse data, and `sc2 graph` writes
a Discourse graph in the output directory.
2020-05-30 14:43:50 -07:00
Dandelion Mané 5279c34c6a
Expose edge-level score flows in timelinePagerank (#1802)
This commit makes a big step towards realizing the v3 output format
(see #1773). Specifically, it modifies the timelinePagerank interval
result format so that in addition to the distribution (the score for
each ndoe), we also track:
- How much score flowed to each node from the seed
- How much score flowed across each edge in a forwards (src->dst)
direction
- How much score flowed across each edge in a backwards (dst->src)
direction
- How much score flowed to each node from its synthetic self loop

The result is that we can now precisely decompose where a node's score
came from (and where it went to). Specficially, for every node we have
the invariant that the node's score is equal to the sum of its seed
score, its synthetic loop score, and the forward flow on each edge for
which the node was dst, and the backward flow for each edge on which the
node was src.

Test plan:
I've added unit tests which verify that the invariant above holds for
real PageRank results on a small example graph.
2020-05-30 14:37:23 -07:00
Dandelion Mané 27aeacc906
Factor out _intervalResult in timelinePagerank (#1799)
As part of work for #1773, I want to add a lot more complexity to the
logic for computing individual time-slices of pagerank scores, so that
we can trace how much score flowed on each individual edge. This means
adding more complexity to the _computeTimelineDistribution function;
however, that function is an untested wrapper, so I'm hesitant to add
more complexity directly.

Instead, I'm first factoring out an _intervalResult method and a
corresponding type, which computes the scores for a given timeline
interval. I've also added sanity checking tests for this method. In a
followon commit, I'll add more logic for tracking edge-level score
flows.

Test plan: This is just a refactor, maintaining existing behavior and
adding tests. `yarn test --full` passes. Since our sharness tests
include doing a full load (including timeline cred computation) on
realistic data from GitHub, this gives us confidence that there hasn't
been any change to cred semantics.
2020-05-30 14:14:32 -07:00
Dandelion Mané 71c0b0d66d
Refactor timelinePagerank, exposing connections (#1797)
This commit refactors internal helper methods in timelinePagerank so
that rather than piping around an OrderedSparseMarkovChain, we instead
provide the NodeToConnections from which that OSMC may be derived. This
is important because the NodeToConnections has the information necessary
to derive how score flowed across individual edges, and not just on the
adjacency topology of the graph. This will allow us to compute the
OutputEdge format with edge-specific cred flows as documented in #1773.

Test plan: `yarn test` passes. It's a simple refactor.
2020-05-30 14:02:23 -07:00
Dandelion Mané d1144217b0
cli2: Use TaskReporters (#1813)
This commit modifies the cli2 interfaces so that plugins may use task
reporters when loading, generating a reference detector, or creating a
graph. Also, the scaffold now automatically reports on task/plugin-level
progress as appropriate.

Test plan: Generate an example instance as described in previous
commits, then run `load` and `graph` and get timing info:

```
~/tmp/instance❯ node $sc/bin/sc2.js load
  GO   load
  GO   loading sourcecred/github
  GO   github: loading sourcecred/example-github
 DONE  github: loading sourcecred/example-github: 220ms
 DONE  loading sourcecred/github: 221ms
 DONE  load: 227ms
~/tmp/instance❯ node $sc/bin/sc2.js graph
  GO   graph
  GO   reference detector
  GO   reference detector for sourcecred/github
 DONE  reference detector for sourcecred/github: 296ms
 DONE  reference detector: 297ms
  GO   sourcecred/github: generating graph
 DONE  sourcecred/github: generating graph: 242ms
 DONE  graph: 544ms
 ```
2020-05-30 12:10:46 -07:00
William Chargin 8d88ea937b
sc2: add graph subcommand (#1811)
Summary:
Paired with @decentralion.

Test Plan:
Follow the test plan for #1810, then additionally run

```
(cd /tmp/test-instance && node "$OLDPWD/bin/sc2.js" graph)
```

and note that the `output/graphs/...` directory has a graph JSON file.

wchargin-branch: cli2-graph
2020-05-28 19:01:03 -07:00
William Chargin 80c3c38282
cli2: add sketch of plugin loading (#1810)
Summary:
This adds a `CliPlugin` interface and a basic implementation for the
GitHub plugin.

Paired with @decentralion.

Test Plan:
Create a new directory `/tmp/test-instance`, with:

```
// sourcecred.json
{"bundledPlugins": ["sourcecred/github"]}

// config/sourcecred/github/config.json
{"repositories": ["sourcecred/example-github"]}
```

Then, run

```
yarn backend &&
(cd /tmp/test-instance && node "$OLDPWD/bin/sc2.js" load)
```

and observe that the new instance has a cache directory containing a
GitHub database.

wchargin-branch: cli2-load
2020-05-28 18:57:27 -07:00
Dandelion Mané 0f6a765569
Refactor TimelineCredScores data type (#1804)
This commit refactors the TimelineCredScores data type so it is an
array-of-objects rather than an object-of-arrays. I want to add several
more fields (for forward cred flow, backwards cred flow, seed flow,
synthetic loop flow), and feel it will be a lot cleaner with an
array-of-objects.

This is a refactor of a local data type, and there's test coverage.
Likelihood of regression is very low.

Test plan: Updated tests; `yarn test` passes.
2020-05-28 18:53:46 -07:00
William Chargin 0449c9ea37
cli2: add skeleton of new CLI (#1809)
Summary:
This patch creates a new binary, `./bin/sc2`, which will be the home for
a rewrite of the CLI intended to implement an instance system. See:
<https://discourse.sourcecred.io/t/sourcecred-instance-system/244>

Paired with @decentralion.

Test Plan:
Run `yarn backend && node ./bin/sc2.js`, which should nicely fail with a
“not yet implemented” message.

wchargin-branch: cli2-skeleton
2020-05-28 18:33:04 -07:00
Dandelion Mané 97da2ae077
Update initiatives plugin to warn on broken urls (#1806)
Currently, if the initiatives plugin is unable to resolve a url, it
simply silently ignores it. This can lead to very big errors in cred
with no clear cause.

We need to address the root cause, but for now this change just makes
the problem more visible--we now print a warning when this happens.

Test plan: When run on the real `MetaFam/TheSource` cred instance, we
now see a lot of warnins printed to console:

```
entry Gitcoin Donation (proofoftom): no address for contributor https://github.com/proofoftom
Gitcoin Donation (adamstallard): no address for contributor https://github.com/adamstallard
Gitcoin Donation (mccallj57): no address for contributor https://github.com/mccallj57
Gitcoin Donation (pet3r-pan): no address for contributor https://github.com/pet3r-pan
Gitcoin Donation (nidea4u): no address for contributor https://github.com/nidea4u
Tavern Keeping (community/DAO management): no address for https://github.com/MetaFam/TheSource/tree/master/initiatives/2020-02-setup-dao.json
Taking Notes: no address for contributor https://github.com/teochiriac
Initiating SourceCred Partnership: no address for https://forum.metagame.wtf/u/hammadj
DAO Setup: no address for https://github.com/pythonpete32
Character Art: no address for https://github.com/kerstentw
Beanow Discord Plugin: no address for contributor https://github.com/Beanow
Intercon: Moderating: no address for https://forum.metagame.wtf/u/FelipeDuarte
Intercon: Moderating: no address for https://github.com/DeFiDude
Intercon: Making NFT Badges: no address for https://github.com/DeFiDude
Intercon: Coordinating Speakers: no address for https://github.com/DeFiDude
Hubs Setup: no address for contributor https://github.com/drewharding
SourceCred Tech Support: no address for https://github.com/Beanow
Setting Up Initiatives/Quest Plugin: no address for https://github.com/Beanow``
```
2020-05-28 18:20:42 -07:00
Dandelion Mané 70a4597610
Update example-github snapshot (#1800)
Without this change, `yarn test --full` fails.
2020-05-18 12:08:57 -07:00